public static void SuppliersData() { using (DbStoreContext context = new DbStoreContext()) { var q = from supplier in context.Set <Supplier>() join supplireprodorder in context.Set <SupplierProductOrder>() on supplier.SupplierId equals supplireprodorder.SupplierId join prodt in context.Set <Product>() on supplireprodorder.ProductId equals prodt.ProductId join prodorder in context.Set <ProductOrder>() on supplireprodorder.ProductOrderId equals prodorder.ProductOrderId select(new { supplier, prodorder, prodt }); foreach (var details in q) { Console.WriteLine($"{details.supplier.SupplierName},{details.supplier.SupplierEmail},{details.supplier.SupplierPhonenumber}" + $"{details.supplier.SupplierAge},{details.prodt.ProductName}"); } } }
public static void ProductCategoryInAscending() { using (DbStoreContext context = new DbStoreContext()) { var query = from category in context.Set <Category>() join prodcategory in context.Set <ProductCategory>() on category.CategoryId equals prodcategory.CategoryId join product in context.Set <Product>() on prodcategory.ProductId equals product.ProductId group product by category.CategoryId into x orderby x.Count <Product>() descending select(new { count = x.Count <Product>(), CategoryId = x.Key }); foreach (var details in query) { Console.WriteLine($"{details.CategoryId} {details.count}"); } } }