using System.Collections.Generic;
public static void Main()
List<MonthlySales> col1 = new List<MonthlySales>
new MonthlySales { Year = 2014, Month= "June", Sales = new Dictionary<string,double> { { "Prod1", 123 }, { "Prod2", 23 } } },
new MonthlySales { Year = 2014, Month= "Aug", Sales = new Dictionary<string,double> { { "Prod3", 12 }, { "Prod4", 55 } } },
List<MonthlySales> col2 = new List<MonthlySales>
new MonthlySales { Year = 2014, Month= "June", Sales = new Dictionary<string,double> { { "Prod3", 12 }, { "Prod2", 10 } } },
new MonthlySales { Year = 2014, Month= "Aug", Sales = new Dictionary<string,double> { { "Prod2", 10 }, { "Prod4", 50 } } },
List<MonthlySales> result = col1.Concat(col2)
.SelectMany(x => x.Sales, (monthhlySalesObj, sale) => new { monthhlySalesObj.Year, monthhlySalesObj.Month, sale })
.GroupBy(x => new { x.Year, x.Month, ProductName = x.sale.Key })
.Select(x => new MonthlySales
Sales = new Dictionary<string, double> { { x.Key.ProductName, x.Sum(z => z.sale.Value) } }
foreach (var item in result)
Console.WriteLine("Year: {0}", item.Year);
Console.WriteLine("Month: {0}", item.Month);
foreach (var sale in item.Sales)
Console.WriteLine("Product Name: {0}", sale.Key);
Console.WriteLine("Sales Price: {0}", sale.Value);
Console.WriteLine("-----------------------------------------");
public class MonthlySales
public int Year { get; set; }
public string Month { get; set; }
public Dictionary<string, double> Sales { get; set; }