Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using (var context = new ProductShopDbContext())
- {
- var selection = context.Categories
- .OrderBy(c => c.Name)
- .Select(c => new
- {
- c.Name,
- ProductsCount = c.CategoryProducts.Count(),
- AvgPrice = c.CategoryProducts.Select(cp => cp.Product.Price).Average(),
- TotalIncome = c.CategoryProducts
- .Where(cp => cp.Product.BuyerId != null)
- .Select(cp => cp.Product.Price).Sum()
- })
- .ToArray();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement