A specified Include path is not valid. The EntityType '' does not declare a navigation property with the name ''

后端 未结 1 1417
独厮守ぢ
独厮守ぢ 2021-01-28 00:26

I wonder if you could help. I get the above error when I call .Include(). It breaks when I include tblMemberships.

this.dbContext.Confi         


        
相关标签:
1条回答
  • 2021-01-28 01:21

    When you write code like this:

    db.ParentTable
        .Include("ChildTable")
        .Include("ChildOfChildTable");
    

    You are saying include all entries from ChildTable that are keyed to ParentTable and also include all entries from ChildOfChildTable that are ALSO keyed to ParentTable. Instead you need to tell Entity Framework that ChildOfChildTable is beneath ChildTable in the hierarchy, like this:

    db.ParentTable
        .Include("ChildTable.ChildOfChildTable");
    

    So this means your code should be:

    this.dbContext.Configuration.LazyLoadingEnabled = false;
    List<tblCustomerInfo> customers = this.dbContext.tblCustomerInfoes
                                          .Include("tblUsers.tblMemberships")
    
    0 讨论(0)
提交回复
热议问题