Friday, October 02, 2009

Linq group by multiple columns

Here is a bit of linq to group by multiple columns. It’s not very well documented so I’ve included a sample below.The trick is to use an anonymous type after the group by clause.

var data3 = from d in db.Assembly_V2s
group d by new { Column1 = d.AssemblyID / 100, Column2 = d.Description.Trim() } into g
orderby g.Key.Column1
select new { Column1 = g.Key.Column1, Column2 = g.Key.Column2 };

No comments: