using System.Collections.Generic;
public static void Main()
List<Categories> categories = new List<Categories>
new Categories { Id =1, CateId =2, CateName = "Cat-B" },
new Categories { Id =2, CateId =1, CateName = "Cat-A" },
new Categories { Id =3, CateId =1, CateName = "Cat-A" },
List<Products> products = new List<Products>
new Products { CategoryId = 1, ProductName ="Product B" },
new Products { CategoryId = 2, ProductName ="Product B" },
new Products { CategoryId = 2, ProductName ="Product C" }
var query = categories.GroupBy(x => new { x.Id, x.CateId, x.CateName })
ProductsNames = products.Where(p => p.CategoryId == x.Key.CateId)
.Select(p => p.ProductName).ToList()
foreach (var item in query)
Console.WriteLine("Id: {0}, CateId: {1}, CateName: {2}", item.Id, item.CateId, item.CateName);
foreach (var productName in item.ProductsNames)
Console.WriteLine(productName);
public int Id { get; set; }
public int CateId { get; set; }
public string CateName { get; set; }
public int CategoryId { get; set; }
public string ProductName { get; set; }