1

我有一个带有重复条目的 IQueryable,我想按出现次数对这个 IQueryable 进行排序。

4

2 回答 2

3

尝试这个:

from e in myQueryable
group e by e.Something into g
order by g.Count()
select g  //Or, g.First()
于 2009-12-09T01:08:29.627 回答
1

像这样:

list
    .GroupBy(x => x.ID)
    .Select(x => new {Obj = x.First(), Count = x.Count()})
    .OrderBy(x => x.Count)
    .Select(x => x.Obj);

不过,我更喜欢 SLaks 的解决方案。

list
    .GroupBy(x => x.ID)             
    .OrderBy(x => x.Count())
    .Select(x => x.First());
于 2009-12-09T01:13:03.443 回答