Reputation: 90465
How do you group by multiple columns in LINQ TO SQL?
db.Table.GroupBy(a => a.column1.ToString() + a.column2.ToString())
It seems ugly and with poor performance, and I don't even know if it works. Which is the right way to do it?
Upvotes: 13
Views: 7561
Reputation: 129782
try grouping by an anonymous type:
group by new { item.Col1, item.Col2 }
you'll then be able to access Key.Col1, etc
Upvotes: 16