2017-02-28 18 views
2

我有以下實體:EF核表達無法綁定

public DbSet<WFPP> WFPPs { get; set; } 
.... 
[Table("PlanningUnit")] 
public class PlanningUnit 
{ 
    public PlanningUnit() 
    { 

    } 

    public int PlanningUnitId { get; set; } 
    public Region Region { get; set; }  

} 


[Table("WFPP")] 
public class WFPP 
{ 
    public WFPP() 
    { 
     AgencyList = new List<PlanningUnit>(); 
    } 

    public int Id { get; set; } 

    public List<PlanningUnit> AgencyList; 

} 

我嘗試如下加載實體:

 var test= _context.WFPPs.Where(x => x.Id==0).Include(x => x.AgencyList).ToList(); 

而且我得到以下錯誤:

The expression '[x].AgencyList' passed to the Include operator could not be bound. 

我找不出是什麼原因導致了這個錯誤,我似乎無法在網上找到很多信息。謝謝。

回答

4
I tested with console app you just need to add get and set. 

    [Table("WFPP")] 
    public class WFPP 
    { 
     public WFPP() 
     { 
      AgencyList = new List<PlanningUnit>(); 
     } 

     public int Id { get; set; } 

     /// your are missing get and set 
     public ICollection<PlanningUnit> AgencyList { get; set; } 

    } 
+0

哇。那些日子中的一天。有時很難將奇怪的錯誤與缺少的簡單事情聯繫起來。非常感謝! –

+0

@JohnEdwards歡迎您。 –