Group Multiple Tables in LINQ

MegaMind picture MegaMind · Jan 4, 2012 · Viewed 43.5k times · Source

I have a very simple SQL query:

SELECT r.SpaceID, Count (*), SpaceCode 
FROM Rider r JOIN Spaces s 
ON r.SpaceID = s.SpaceID
GROUP BY r.SpaceID, s.SpaceCode 

Please note that my group by clause is on multiple tables, I want to do the same in LINQ, I know how to group single table, but about multiple tables I have no idea.

Answer

Pankaj Tiwari picture Pankaj Tiwari · Jan 4, 2012

For grouping multiple tables you can do as:

group new { r,s } by new { r.SpaceID, s.SpaceCode }