查询与distinct和order by

时间:2014-01-09 23:59:30

标签: linq-to-sql

我有这个数据集

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

但我正在努力的是什么?

1 个答案:

答案 0 :(得分:0)

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