我在从linq查询中获得预期结果时遇到了一些麻烦。
以下是一些示例数据:
Queue Priority TTRDate
Main Critical 6/9/2014 7:41:00 PM
Main Major 6/9/2014 7:42:00 PM
Main Critical 6/9/2014 7:43:00 PM
Main Minor 6/9/2014 7:30:00 PM
Main Minor 6/9/2014 7:35:00 PM
查询:
listTickets = queryAllTickets.Where(y => y.Queue == "Main")
.OrderBy(t => t.Priority == "Critical")
.ThenBy(x => x.TTRDate)
.Take(numberOfrecords)
.ToList();
预期结果:
Main Critical 6/9/2014 7:41:00 PM
Main Critical 6/9/2014 7:43:00 PM
Main Minor 6/9/2014 7:30:00 PM
Main Minor 6/9/2014 7:35:00 PM
Main Major 6/9/2014 7:42:00 PM
简单来说,我想要通过TTRdate订购的关键物品,然后我想要TTRDate订购的所有其他物品。
答案 0 :(得分:4)
false
小于true
,因此您需要OrderByDescending
:
.OrderByDescending(t => t.Priority == "Critical")
或使用!=
代替==
:
.OrderBy(t => t.Priority != "Critical")