Entity Framework - Selective Condition on Included Navigation Property

前端 未结 3 1762
花落未央
花落未央 2020-12-20 18:22

Assume I have these simplified EF generated entities...

public class PurchaseOrder
{
     public int POID {get;set;}
     public int OrderID         


        
3条回答
  •  攒了一身酷
    2020-12-20 18:58

    You can't selectively pull back certain child entities that match a certain condition. The best you can do is manually filter out the relevant orders yourself.

    public class PurchaseOrder
    {
         public int POID {get;set;}
         public int OrderID {get;set;}
         public int VendorID {get;set;}
         public IEnumerable Orders {get;set;}
    
         public IEnumerable MatchingOrders {
             get {
                return this.Orders.Where(o => o.VendorId == this.VendorId);
             }
         }
    }
    

提交回复
热议问题