The code below creates a list of strings. The grouping factor is the StoreID (Item1). What I want is a dictionary with the grouping factor (i.e. StoreID) as the key and the string as the value. The input file is just a text file that contains 3 columns: StoreID, Quantity, and something else (which I can’t remember) but these values are just concatenated together for each line for a store to make a comma and bar separated string.
var query = skuStoreStockLevel.GroupBy(x => x.Item1)
.Select(g => g.Aggregate(new StringBuilder(),
(sb, x) => sb.AppendFormat("{0}{1},{2},{3}", "|", x.Item1, x.Item2, x.Item3),
(sb) => sb.ToString()));
You can use Enumerable.ToDictionary to do this: