Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string GetTotalProfitByCategory(BookShopContext db)
- {
- var books = db.Categories
- .Select(x => new
- {
- name = x.Name,
- profit = x.CategoryBooks.Sum(a => a.Book.Price * a.Book.Copies)
- })
- .OrderByDescending(x => x.profit)
- .ThenBy(x => x.name)
- .ToList();
- return string.Join(Environment.NewLine, books.Select(x => $"{x.name} ${x.profit:f2}"));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement