EF Core Expression Could Not Be Bound

entity-framework entity-framework-core

Question

I have the following entities:

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;

}

I try to load the entities as follows:

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

And I get the following error:

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

I cannot figure out what is causing this error, and I cannot seem to find much information online. Thanks.

1
2
2/28/2017 4:44:18 AM

Accepted Answer

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

    }
4
2/28/2017 8:32:17 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow