2014-01-09 73 views
0

我有這個數據集查詢具有鮮明和ORDER BY

Id  TypeId  Description 
------------------------------- 
1  1   happy 
2  1   sad 
3  2   sad 
4  2   sad 
5  3   upset 
6  1   upset 
7  2   chilaxing 
8  4   happy 

,我試圖讓LINQ做到這一點:

select count(Id) as count, Type from MyDate 
group by Description 
order by count desc 

所以我得到:

count Type 
------------ 
3  sad 
2  happy 
2  upset 
1  chilaxing 

但是我正在嘗試的是沒有工作?

回答

0
from d in data 
group d by d.description into g 
orderby g.Count() desc 
select new {g.Key, Count = g.Count()} 
+0

好溫你這樣做,它似乎很明顯:) – user2472565