I have a Product class something like:
class Product { public string Name; public int Year; public int Vendor; public int Count; } Data input like
Name Year Vendor Count 'A' 1990 1 15 'A' 1990 2 20 'A' 1998 4 5 'B' 1995 1 15 'B' 1995 2 2 I want to transform the data into a new structure like
class NewStructure { public string Name; public int Year; Dictionary<int, int> Vendor_Count; } The Dictionary field is used to store {Vendor, Count} pair, the pair of Name and Year would have a correspodning dictionary. The result would be
Name Year Vendor Count 'A' 1990 1 15 2 20 'A' 1998 4 5 'B' 1995 1 15 2 2 I tried the following linq query
from input in inputList group inputList by new { input.Name, input.Year } into grouping orderby grouping.Key.Name, grouping.Key.Year select new { ProductName = grouping.Key.Name, OriginYear = grouping.Key.Year, Vendor_Count = grouping. } But I can't get the 'Vendor_Count' right. I wonder what should I do?