如何实现case功能
如何用linq实现以下sql语句
SELECT * from
order by case TABLE_NAME
when '值1' then 9
when '值2' then 8
when '值3' then 7
else
1
end desc
[解决办法]
用三目运算可以实现,
[解决办法]
int OrderTable(string table_name)
{
switch(table_name)
{
case "值1" : return 9;
case "值2" : return 8;
case "值3" : return 7;
case "值4" : return 6;
case "值5" : return 5;
...
defult: return 1;
}
}
var query=db.Users.OrderByDescending(u=>OrderTable(u.table_name));