I' ve got tables: Customer, Order, Product
Customer has gor a lot of orders, each order has got a lot wof products.
How can I write query to get all products from Customer ? I need to use it as a datasource, thanks for help bye
I' ve got tables: Customer, Order, Product
Customer has gor a lot of orders, each order has got a lot wof products.
How can I write query to get all products from Customer ? I need to use it as a datasource, thanks for help bye
This should work:
var result = customer
.SelectMany(x=>x.Orders)
.Select(x=>x.Products)
Also you can add .Distinct() to retrieve only different products
Another way is to go from Products:
var result = dbContext.Products
.Where(x=>x.Orders.Any(o=>o.Customer.Id == customer.Id))
Hard to read and hard to understand, but still works)