Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string GetSoldProducts(ProductShopContext context)
- {
- var soldProducts = context.Users
- // .Where(x => x.ProductsSold.Any(a => a.BuyerId != null))
- .Select(u => new
- {
- firstName = u.FirstName,
- lastName = u.LastName,
- soldProducts = u.ProductsSold
- .Where(x => x.BuyerId != null)
- .Select(p => new
- {
- name = p.Name,
- price = p.Price,
- buyerFirstName = p.Buyer.FirstName,
- buyerLastName = p.Buyer.LastName
- })
- })
- .OrderBy(u => u.lastName)
- .ThenBy(u => u.firstName)
- .ToList();
- return JsonConvert.SerializeObject(soldProducts, Formatting.Indented);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement