using System.Collections.Generic;
public static void Main()
List<Product> products = new List<Product>
new Product { ProductID = 1, CategoryID = 10, CategoryName = "Electronics", DateLastModified = new DateTime(2014,06,12) },
new Product { ProductID = 2, CategoryID = 11, CategoryName = "Beverages", DateLastModified = new DateTime(2014,05,01) },
new Product { ProductID = 3, CategoryID = 10, CategoryName = "Electronics", DateLastModified = new DateTime(2014,06,28) },
new Product { ProductID = 4, CategoryID = 11, CategoryName = "Beverages", DateLastModified = new DateTime(2014,06,12) },
new Product { ProductID = 5, CategoryID = 10, CategoryName = "Electronics", DateLastModified = new DateTime(2014,10,13) },
new Product { ProductID = 6, CategoryID = 11, CategoryName = "Beverages", DateLastModified = new DateTime(2014,05,10) },
var query = from pro in products
group pro by pro.CategoryName into newGroup1
group prod by new { prod.DateLastModified.Year, prod.DateLastModified.Month }
group newGroup2 by newGroup1.Key;
foreach (var categories in query)
Console.WriteLine("Category Name : {0}",categories.Key);
foreach (var modifiedDates in categories)
Console.WriteLine("Year : {0}, Month : {1}", modifiedDates.Key.Year, modifiedDates.Key.Month);
foreach (var prods in modifiedDates)
Console.WriteLine(prods.ProductID);
public int ProductID { get; set; }
public int CategoryID { get; set; }
public string CategoryName { get; set; }
public DateTime DateLastModified { get; set; }