Advertisement
Guest User

Untitled

a guest
Jul 27th, 2015
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. // Problem 03, query 02 - Successfully Sold Products
  2.             var usersWithProductSales = context.Users
  3.                 .Where(u => u.SoldProducts.Any())
  4.                 .Select(u => new
  5.                 {
  6.                     firstName = u.FirstName ?? "-",
  7.                     lastName = u.LastName,
  8.                     soldProducts = u.SoldProducts.Select(p => new
  9.                     {
  10.                         name = p.Name,
  11.                         price = p.Price,
  12.                         buyerFirstName = p.Buyer.FirstName ?? "-",
  13.                         buyerLastName = p.Buyer.LastName
  14.                     })
  15.                 });
  16.  
  17. // Problem 03, query 04 - Users and Products
  18.             var usersWithSoldProducts = context.Users
  19.                 .Where(u => u.SoldProducts.Any())
  20.                 .OrderByDescending(u => u.SoldProducts.Count)
  21.                 .ThenBy(u => u.LastName)
  22.                 .Select(u => new
  23.                 {
  24.                     firstName = u.FirstName ?? "-",
  25.                     lastName = u.LastName,
  26.                     age = u.Age,
  27.                     products = u.SoldProducts.Select(p => new
  28.                     {
  29.                         name = p.Name,
  30.                         price = p.Price
  31.                     })
  32.                 });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement