using System.Collections.Generic;
public static void Main()
var firms = FirmRepository.Get();
var pricesPerWeek = firms
.Where(firm => firm.Id == 1)
.SelectMany(firm => firm.Prices)
productPrice => productPrice.Year == DateTime.Now.Year &&
productPrice.ProductId == 1)
.Select(productPrice => new {productPrice.Week, productPrice.Price})
pricesPerWeek.ForEach(x => Console.WriteLine("Week {0}: {1}",x.Week,x.Price));
Prices = new List<ProductPrice>();
public String Name {get;set;}
public List<ProductPrice> Prices {get; private set;}
public class ProductPrice
public int FirmId {get;set;}
public int ProductId {get;set;}
public int Year {get;set;}
public int Week {get;set;}
public decimal Price {get;set;}
public String Description {get;set;}
public class FirmRepository
public static IEnumerable<Firm> Get()
var firms = new List<Firm>();
var firm = new Firm {Id = 1, Name = "ABC" };
firm.Prices.Add(new ProductPrice {FirmId = 1, ProductId = 1, Year = 2015, Week = 52, Price = 1.65m});
firm.Prices.Add(new ProductPrice {FirmId = 1, ProductId = 1, Year = 2016, Week = 1, Price = 1.65m});
firm.Prices.Add(new ProductPrice {FirmId = 1, ProductId = 1, Year = 2016, Week = 2, Price = 1.68m});
firm.Prices.Add(new ProductPrice {FirmId = 1, ProductId = 1, Year = 2016, Week = 3, Price = 1.75m});
firm.Prices.Add(new ProductPrice {FirmId = 1, ProductId = 1, Year = 2016, Week = 4, Price = 1.99m});
firm.Prices.Add(new ProductPrice {FirmId = 1, ProductId = 2, Year = 2015, Week = 52, Price = 11.65m});
firm.Prices.Add(new ProductPrice {FirmId = 1, ProductId = 2, Year = 2016, Week = 1, Price = 12.65m});
firm.Prices.Add(new ProductPrice {FirmId = 1, ProductId = 2, Year = 2016, Week = 2, Price = 13.68m});
firm.Prices.Add(new ProductPrice {FirmId = 1, ProductId = 2, Year = 2016, Week = 3, Price = 14.75m});
firm.Prices.Add(new ProductPrice {FirmId = 1, ProductId = 2, Year = 2016, Week = 4, Price = 15.99m});
firm = new Firm {Id = 2, Name = "DEF" };
firm.Prices.Add(new ProductPrice {FirmId = 2, Year = 2016, Week = 1, Price = 2.65m});
firm.Prices.Add(new ProductPrice {FirmId = 2, Year = 2016, Week = 2, Price = 2.68m});
firm.Prices.Add(new ProductPrice {FirmId = 2, Year = 2016, Week = 3, Price = 2.75m});
firm.Prices.Add(new ProductPrice {FirmId = 2, Year = 2016, Week = 4, Price = 2.99m});
firm = new Firm {Id = 3, Name = "GHI" };
firm.Prices.Add(new ProductPrice {FirmId = 3, Year = 2016, Week = 1, Price = 3.65m});
firm.Prices.Add(new ProductPrice {FirmId = 3, Year = 2016, Week = 2, Price = 3.68m});
firm.Prices.Add(new ProductPrice {FirmId = 3, Year = 2016, Week = 3, Price = 3.75m});
firm.Prices.Add(new ProductPrice {FirmId = 3, Year = 2016, Week = 4, Price = 3.99m});
firm = new Firm {Id = 4, Name = "JKL" };
firm.Prices.Add(new ProductPrice {FirmId = 4, Year = 2016, Week = 1, Price = 4.65m});
firm.Prices.Add(new ProductPrice {FirmId = 4, Year = 2016, Week = 2, Price = 4.68m});
firm.Prices.Add(new ProductPrice {FirmId = 4, Year = 2016, Week = 3, Price = 4.75m});
firm.Prices.Add(new ProductPrice {FirmId = 4, Year = 2016, Week = 4, Price = 4.99m});