我有以下 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 升序排列。我在分数下降之后。
谢谢 :)
我有以下 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 };
var results =
(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) })
.OrderByDescending(p=>p.Score);
希望这能解决你的问题,比上面的更容易;)
干杯