How .GroupBy multiple LINQ / Projection columns?

How can I group by multiple columns using linq projection?

Something like that:

var q = db.Areas.GroupBy(x => x.AreaCatId, x.AreaCatName, x.AreaId, x.AreaName); 

The result is in a flat result set, for example:

 AreaCatId, AreaCatName, AreaId, AreaName 0 US 1 FL 0 US 2 NY 1 Canada 3 BC 
+4
source share
1 answer

You can GroupBy anonymous type:

 var q = db.Areas.GroupBy( x => new { CatId = x.AreaCatId, CatName = x.AreaCatName, Id = x.AreaId, Name = x.AreaName }); 
+5
source

Source: https://habr.com/ru/post/1383130/


All Articles