linq 我将如何订购此声明
linq how would i order this statement
如您所见,我正在尝试在语句末尾执行多个 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);
使用ThenByDescending
方法按降序应用二次排序。
.OrderBy(x => x.httitle).ThenByDescending(x => x.totalHrs);
如果您要链接多个 OrderBy()
查询,您需要使用 ThenBy()
和 ThenByDescending()
来获取后续属性,以便它们以正确的顺序应用:
.OrderBy(x => x.httitle).ThenByDescending(x => x.totalHrs);
如您所见,我正在尝试在语句末尾执行多个 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);
使用ThenByDescending
方法按降序应用二次排序。
.OrderBy(x => x.httitle).ThenByDescending(x => x.totalHrs);
如果您要链接多个 OrderBy()
查询,您需要使用 ThenBy()
和 ThenByDescending()
来获取后续属性,以便它们以正确的顺序应用:
.OrderBy(x => x.httitle).ThenByDescending(x => x.totalHrs);