Advertisement
butoff

Untitled

Dec 4th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.91 KB | None | 0 0
  1.             using (var context = new ProductShopDbContext())
  2.             {
  3.                 var selection = context.Categories
  4.                                        .OrderBy(c => c.Name)
  5.                                        .Select(c => new
  6.                                        {
  7.                                            c.Name,
  8.                                            ProductsCount = c.CategoryProducts.Count(),
  9.                                            AvgPrice = c.CategoryProducts.Select(cp => cp.Product.Price).Average(),
  10.                                            TotalIncome = c.CategoryProducts
  11.                                                           .Where(cp => cp.Product.BuyerId != null)
  12.                                                           .Select(cp => cp.Product.Price).Sum()
  13.                                        })
  14.                                        .ToArray();
  15.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement