I have two tables with a one to many relation.
One Order has many Products.
I want to take a list of Orders with the free Product in each (one per order).
I’ve tried something like this:
this.ObjectContext.ORDERS.Include("PRODUCTS").Where(e=>e.PRODUCTS.price == 0).OrderBy(e => e.Order);
But this is not working.
Is there any other approach??
Thanks in advance.
if
PRODUCTSis a collection, you can use theAny()extension method to find out if any product is free (alternatively, theAll()method to find out if all products are free):Based on your clarification of the desired output (all orders with optional free product), you can use this query:
It will return a sequence of an anomymous type containing the order, and the free product (or null if no free product exists).