Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var users = context.Users
- .Where(u => u.ProductsSold.Any(ps => ps.Buyer != null))
- .OrderByDescending(u => u.ProductsSold.Any(ps => ps.Buyer != null))
- .Select(u => new
- {
- firstName = u.FirstName,
- lastName = u.LastName,
- age = u.Age,
- count = u.ProductsSold.Count(p => p.Buyer != null),
- products = u.ProductsSold
- .Where(ps => ps.Buyer != null)
- .Select(ps => new
- {
- name = ps.Name,
- price = ps.Price
- }).ToList()
- }).ToList();
- var json = JsonConvert.SerializeObject(users, Formatting.Indented);
- return json;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement