Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you group by multiple columns in LINQ TO SQL?

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?

like image 515
Jader Dias Avatar asked Jul 10 '09 14:07

Jader Dias


1 Answers

try grouping by an anonymous type:

group by new { item.Col1, item.Col2 }

you'll then be able to access Key.Col1, etc

like image 200
David Hedlund Avatar answered Oct 16 '22 11:10

David Hedlund