[英]linq how would i order this statement
如您所見,我正在嘗試在語句末尾執行多個by 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);
如果要鏈接多個OrderBy()
查詢,則需要使用ThenBy()
和ThenByDescending()
為其后續屬性按適當順序應用它們:
.OrderBy(x => x.httitle).ThenByDescending(x => x.totalHrs);
使用ThenByDescending
方法以降序應用二級排序。
.OrderBy(x => x.httitle).ThenByDescending(x => x.totalHrs);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.