I have an IQueryable with duplicate entries and I want to sort this IQueryable by the count of occurrences.
+2
A:
Try this:
from e in myQueryable
group e by e.Something into g
order by g.Count()
select g //Or, g.First()
SLaks
2009-12-09 01:08:29
cool it works..!
Ashish
2009-12-09 01:34:07
is there anyway to get the maximum occurring element first than the least.
Ashish
2009-12-09 02:06:03
never mind got it..
Ashish
2009-12-09 02:10:41
+1
A:
Like this:
list
.GroupBy(x => x.ID)
.Select(x => new {Obj = x.First(), Count = x.Count()})
.OrderBy(x => x.Count)
.Select(x => x.Obj);
I like SLaks' solution more, though.
list
.GroupBy(x => x.ID)
.OrderBy(x => x.Count())
.Select(x => x.First());
Mike Chaliy
2009-12-09 01:13:03