![](/img/trans.png)
[英]C# LINQ Orderby on parent only in hierarchical parent-child relationship data
[英]Sorting Parent-Child with orderby linq
據我所知,預期的結果是先按ID列排序,但從1004到1001,這意味着您需要按降序對其進行排序。 請改用Enumerbale.OrderByDescending和Enumerable.ThenByDescending 。
您應該嘗試:
var result = qry.OrderByDescending(j => j.Id).
ThenBy(j => j.SubId).
ThenBy(j => j.JobName).
ThenByDescending(j => j.DocumentGroupId).ToList();
同樣,擁有更多有關如何分類的細節也將是很棒的。 不只是預期結果屏幕。
像這樣?
qry =
qry
.GroupBy(j => j.Id)
.OrderBy(group => group
.Single(j => j.SubId == 0)
.Name)
.SelectMany(group => group
.OrderBy(j => j.SubId))
.ToList();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.