如何在LINQ中编写以下sql代码
select count(1) Cnt,state
from yourtable
group by state
order by Cnt desc Limit 5
我正在尝试这样的事情
(from topPro in CS.state group topPro by new {
Name = topPro.state.Name
} into g
select new{
StateName = g.Key.Name,
Count = g.Count(x=>x.state)
}
答案 0 :(得分:1)
我得到了答案
var top5Pros = (from topPro in CS.state
group topPro by new { Name = topPro.state.Name } into g
select new
{
StateName = g.Key.Name,
Count = g.Count()
}).OrderByDescending(w => w.Count).Take(5);