Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem 03, query 02 - Successfully Sold Products
- var usersWithProductSales = context.Users
- .Where(u => u.SoldProducts.Any())
- .Select(u => new
- {
- firstName = u.FirstName ?? "-",
- lastName = u.LastName,
- soldProducts = u.SoldProducts.Select(p => new
- {
- name = p.Name,
- price = p.Price,
- buyerFirstName = p.Buyer.FirstName ?? "-",
- buyerLastName = p.Buyer.LastName
- })
- });
- // Problem 03, query 04 - Users and Products
- var usersWithSoldProducts = context.Users
- .Where(u => u.SoldProducts.Any())
- .OrderByDescending(u => u.SoldProducts.Count)
- .ThenBy(u => u.LastName)
- .Select(u => new
- {
- firstName = u.FirstName ?? "-",
- lastName = u.LastName,
- age = u.Age,
- products = u.SoldProducts.Select(p => new
- {
- name = p.Name,
- price = p.Price
- })
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement