Home > Blockchain >  LINQ Group By and merge properties and Summarize the Invoice Number
LINQ Group By and merge properties and Summarize the Invoice Number

Time:11-03

I have the follow List(InputData), and I would like to group by Vendor then by Type and Summarize by NumberInvoice and Concatenate by Month enter image description here

CodePudding user response:

This will work

            var result = InputData
                .OrderBy(x => x.Month)
                .GroupBy(x => x.Month)
                .SelectMany(x => x.GroupBy(y => new {y.Vendor, y.Type, y.NumberInvoice})
                .Select(y => new { Vendor = y.Key.Vendor, Type = y.Key.Type, month = x.Key, numberInvoices = y.Count()}).ToList()).ToList();
  • Related