linq 中的分组查询
直接看代码:
//一个字段分组
var data1 = from a in query
group a by a.Name into b
select new
{
Total = b.Sum(c=>c.BrowseRealCount),
Id = b.Select(c=>c.Id)
};
//多个字段分组,可以使用匿名类方式
var data2 = from a in query
group a by new { a.Name, a.Summary } into b
select new
{
Total = b.Sum(c => c.BrowseRealCount),
Id = b.Select(c => c.Id)
};
//按某字段分组后获取分组后的集合
var user = query.GroupBy(c => c.Name, (i, v) => new
{
ID = i,
uList = v
});
var list = user.ToList();