如何将此Query转换为Linq

时间:2014-06-01 13:47:02

标签: c# asp.net linq linq-to-sql

如何将此查询转换为linq:

Select top 1 COUNT(*)
From RateTable
Group by Rate
order by COUNT(*) desc

这个表SQL是:

Create Table RateTable ( RID int primary key , Rate int );

1 个答案:

答案 0 :(得分:0)

db.RateTable
  .GroupBy(x => x.Rate) 
  .Select(g => g.Count())
  .OrderByDescending(g => g) 
  .First()