A规定包括路径无效。该的EntityType'''不具有名称申报导航属性“ [英] A specified Include path is not valid. The EntityType '' does not declare a navigation property with the name ''

查看:1164
本文介绍了A规定包括路径无效。该的EntityType'''不具有名称申报导航属性“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道你能不能帮。我得到了上面的错误,当我打电话 .INCLUDE()。它打破了,当我包括 tblMemberships

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

this.dbContext.Configuration.LazyLoadingEnabled = false;
List<tblCustomerInfo> customers = this.dbContext.tblCustomerInfoes.Include("tblUsers").Include("tblMemberships").ToList();

究其原因是因为和 tblMemberships 不存在 tblCustomerInfo 之间的导航属性。 向tblUsers 是其他两个表之间的联系。

The reason is because the navigation property between tblCustomerInfo and tblMemberships does not exist. tblUsers is the link between the other two tables.

Customer -- 1:* -- User -- 1:* -- Membership

(对不起,不能包含图像作为我reputataion小于10)。

(Sorry, can't include image as my reputataion < 10).

我的问题是:


  1. 我需要什么,才能有 tblMemberships 包含?
  2. 来办
  3. 这是检索数据,或者我应该把它分解成两个查询推荐的方法?或者设计完全是垃圾?

我使用EF5,ASP .NET MVC 4

I am using EF5, ASP .NET MVC 4

请告知。谢谢你。

推荐答案

当你写code是这样的:

When you write code like this:

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

您是说包括 ChildTable 所有条目被键入到 ParentTable ,也包括从<$所有条目C $ C> ChildOfChildTable 同时也是键控 ParentTable 。相反,你需要告诉实体框架是 ChildOfChildTable 是下面 ChildTable 层次结构中,像这样的:

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");

因此​​,这意味着你的code应该是:

So this means your code should be:

this.dbContext.Configuration.LazyLoadingEnabled = false;
List<tblCustomerInfo> customers = this.dbContext.tblCustomerInfoes
                                      .Include("tblUsers.tblMemberships")

这篇关于A规定包括路径无效。该的EntityType'''不具有名称申报导航属性“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆