欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

C# Linq group by 多个字段

程序员文章站 2022-07-04 10:19:48
...
  var result = (
                from meta in metaErrorInfos
                group meta by new
                {
                    meta.SchemaInfoId,
                    meta.SchemaName
                } into t
                select new
                {
                    SchemaInfoId = t.Key.SchemaInfoId,
                    SchemaName = t.Key.SchemaName,
                    Tec = t.Max(x => x.Tec),
                    Line = t.Max(x => x.Line),
                    MailTo = t.Max(x => x.MailTo),
                    Version = t.Max(x => x.Version),
                    CategoryName = t.Max(x => x.CategoryName),
                    ErrorItemTotalCount = t.Count(),
                    ErrorItems = t.GroupBy(x => x.ErrorItem).Select(x => new { name = x.Key, repeat = x.Count() }).ToList(),
                    MetaPath = t.Select(a => a.MetaPath).ToList()
                }).ToList();