如您所见,我试图在声明结尾处执行多个order by语句。我的结果没有回复正确。
var query =
(from x in workloadDetail
group x by new { x.titleOrder, x.httitle } into sortedData
select new WorkloadSummary()
{
httitle = sortedData.Key.httitle,
totalHrs = sortedData.Sum(x => x.totalHrs),
totalDol = sortedData.Sum(x => x.totalDol),
titleOrder = sortedData.Key.titleOrder
}).OrderBy(x => x.httitle).OrderByDescending(x => x.totalHrs);
答案 0 :(得分:5)
如果您要链接多个OrderBy()
个查询,则需要使用ThenBy()
和ThenByDescending()
作为后续属性,以便按正确的顺序应用它们:
.OrderBy(x => x.httitle).ThenByDescending(x => x.totalHrs);
答案 1 :(得分:4)
使用ThenByDescending
方法按降序应用二级排序。
.OrderBy(x => x.httitle).ThenByDescending(x => x.totalHrs);