MS SQL OrderBy设置标准组

时间:2014-06-04 15:17:08

标签: c# sql sql-server linq

我需要将这个Linq OrderBy语句翻译成SQL:

list = list.OrderByDescending(x => x.Gender == "f" && x.IsCouple == 0)
           .ThenByDescending(x => x.ApprovalRejectedDate)
           .ThenByDescending(x => x.Id);

只需:

ORDER BY x.Gender, x.IsCouple, x.ApprovalRejectedDate, x.Id 

返回不同的顺序,因为第一组标准需要匹配在一起。

我在SQL中如何做到这一点?

1 个答案:

答案 0 :(得分:2)

order by
 case when x.Gender = 'f' and x.IsCouple = 0 then 1 else 0 end,
 x.ApplrovalRejectedDate desc,
 x.Id desc