How do I order a Group result, in Linq?

后端 未结 2 1415
迷失自我
迷失自我 2020-12-24 01:19

I have the following linq query, which works fine. I\'m not sure how i order the group\'d result.

from a in Audits
join u in Users on a.UserId equals u.UserI         


        
2条回答
  •  有刺的猬
    2020-12-24 01:49

    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);
    

    Hope this will fix your problem, easier than the top one ;)

    Cheers

提交回复
热议问题