我有以下 linq 查询,效果很好。我不确定如何对分组结果进行排序。
from a in Audits
join u in Users on a.UserId equals u.UserId
group a by a.UserId into g
select new { UserId = g.Key, Score = g.Sum(x => x.Score) }
结果当前按 UserId 升序排序。我追求分数下降。
谢谢:)
最佳答案
只需添加 orderby 子句;-)
from a in Audits
join u in Users on a.UserId equals u.UserId
group a by a.UserId into g
let score = g.Sum(x => x.Score)
orderby score descending
select new { UserId = g.Key, Score = score };
关于linq - 如何在 Linq 中订购组结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/755132/