EF核心表達無法綁定

entity-framework entity-framework-core

我有以下實體:

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.

我無法弄清楚是什麼導致了這個錯誤,我似乎無法在網上找到太多信息。謝謝。

一般承認的答案

  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; }

    }


Related

許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow