Linq to Entities simple group query
1 answer
var query = answers
.GroupBy(a => a.answernumber, a => a, (k, g) => new {answernumber = k, Count = g.Count()})
.OrderyBy(i => i.answernumber);
Or in another way:
var query2 = from a in answers
group a by a. answernumber into g
orderby g.Key
select new { answernumber = g.Key, Count = g.Count() };
+4
source to share