public static void linq6() { //Create linq query which returns all categories together with their products //Create class CategoryWithProduct which should keep the result the class CategoryWithProduct must conrtain the following //properties : CategoryName : string, ProductNames : List<string>, CategoryId : int List <Product> listOfProducts = Product.GetProducts; List <Category> listOfCategories = Category.GetCategories; var listOfAllProdsAndCates = from cate in listOfCategories join prod in listOfProducts on cate.CategoryID equals prod.CategoryID orderby cate.CategoryID select new { cate.CategoryID, prod.ProductID, prod.Name, cate.CategoryName }; foreach (var item in listOfAllProdsAndCates) { CategoryWithProduct catewprod = new CategoryWithProduct(item.CategoryName, item.ProductID, listOfProducts); Console.WriteLine(item.CategoryID + "product ID is " + item.ProductID + ", " + item.Name); } }
public static void linq6() { //Create linq query which returns all categories together with their products //Create class CategoryWithProduct which should keep the result the class CategoryWithProduct must conrtain the following //properties : CategoryName : string, ProductNames : List<string>, CategoryId : int List<Product> listOfProducts = Product.GetProducts; List<Category> listOfCategories = Category.GetCategories; var listOfAllProdsAndCates = from cate in listOfCategories join prod in listOfProducts on cate.CategoryID equals prod.CategoryID orderby cate.CategoryID select new { cate.CategoryID, prod.ProductID,prod.Name,cate.CategoryName }; foreach (var item in listOfAllProdsAndCates) { CategoryWithProduct catewprod = new CategoryWithProduct(item.CategoryName, item.ProductID, listOfProducts); Console.WriteLine(item.CategoryID + "product ID is " + item.ProductID + ", " + item.Name); } }