簡體   English   中英

linq我將如何訂購此聲明

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM