1. 程式人生 > >linq實現行轉列

linq實現行轉列

nt maxcount = Model
        .SelectMany(h => h.DetailList).OrderBy(h => h.DetailType)
        .GroupBy(h => h.DetailType).Select(h => h.Count()).Max();
    int Fitsetcount = Model.SelectMany(h => h.DetailList).OrderBy(h => h.DetailType)
          .GroupBy(h => h.DetailType).FirstOrDefault
().Count(); List<List<Model>> QuantumList= Model .SelectMany(h => h.DetailList).OrderBy(h => h.DetailType) .GroupBy(h => h.DetailType).Skip(1) .Aggregate(Model.SelectMany(h => h.DetailList).OrderBy(h => h.DetailType) .GroupBy(h => h.DetailType
).FirstOrDefault().OrderBy(h=>h.FSeq) .Select(h => new List<Model>() { h }).Union(System.Linq.Enumerable.Repeat(new List<Model>() { new Model() }, Math.Abs(maxcount - Fitsetcount)).ToList()), (t, s) => t.Zip(s.OrderBy(h => h.FSeq).Select(h => new List<Model>() { h }).Union
(System.Linq.Enumerable.Repeat(new List<Model>(){new Model()}, Math.Abs(maxcount - s.Count())).ToList()), (n, m) => n.Concat(m).ToList()) ).ToList();