如何使用linq投影将多列分组?
这样的事情:
var q = db.Areas.GroupBy(x => x.AreaCatId, x.AreaCatName, x.AreaId, x.AreaName);
导致平面结果集,例如:
AreaCatId, AreaCatName, AreaId, AreaName
0 US 1 FL
0 US 2 NY
1 Canada 3 BC
答案 0 :(得分:5)
您可以将GroupBy设为匿名类型:
var q = db.Areas.GroupBy(
x => new
{
CatId = x.AreaCatId,
CatName = x.AreaCatName,
Id = x.AreaId,
Name = x.AreaName
});