Suppose I have these simplified generated EF objects ...
public class PurchaseOrder { public int POID {get;set;} public int OrderID {get;set;} public int VendorID {get;set;} public IEnumerable<Order> Orders {get;set;} } public class Order { public int OrderID {get;set;} public decimal Price {get;set;} public IEnumerable<Item> Items {get;set;} } public class Item { public int OrderID {get; set;} public string SKU {get;set;} public int VendorID {get;set;} public Order Order {get;set;} }
Business logic:
An order can have several POs, one for each individual supplier in the order (suppliers are defined at the element level).
How can I selectively include child objects?
When requesting PO addresses, I want to automatically include child elements for Order and Item.
I accomplish this using Include () ...
Context.PurchaseOrders.Include("Orders.Items");
This does the job and discards related objects, but I want to include Item objects whose VendorID matches the VendorID of the PurchaseOrder .
With traditional SQL, I would just include this in the JOIN clause, but EF builds them inside.
What LINQ magic can I use to tell EF to apply the condition without manually creating a JOIN between entities?
ctorx source share