C# Linq group by 多个字段

  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();

猜你喜欢

转载自blog.csdn.net/weixin_44566738/article/details/87777460