Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework 包含路径表达式必须引用在类型上定义的导航属性_Entity Framework_Entity Framework 4.1 - Fatal编程技术网

Entity framework 包含路径表达式必须引用在类型上定义的导航属性

Entity framework 包含路径表达式必须引用在类型上定义的导航属性,entity-framework,entity-framework-4.1,Entity Framework,Entity Framework 4.1,我有以下存储库方法:- public AccountDefinition GetCustomer2(int id) { var c = entities.AccountDefinitions .Where(p=>p.ORG_ID==id) .Include(a => a.SDOrganization) .Include(a2 => a2.SiteDefinitions) .I

我有以下存储库方法:-

public AccountDefinition GetCustomer2(int id)
{
    var c = entities.AccountDefinitions
            .Where(p=>p.ORG_ID==id)
            .Include(a => a.SDOrganization)
            .Include(a2 => a2.SiteDefinitions)
            .Include(a3 => a3.SDOrganization.AaaPostalAddresses)
            .Include(a4 => a4.SiteDefinitions.SelectMany
                              (a5 => a5.DepartmentDefinitions.SelectMany
                                    (a6 => a6.SDUsers.Select
                                          (a7 => a7.AaaUser))))
                                                   .SingleOrDefault();

    return c;
}
调用上述方法的操作方法如下:-

public ActionResult Details2(int id = 0)
{
    AccountDefinition cd = repository.GetCustomer2(id);
    return View("copy",cd);
}
但是当我导航到Action方法时,我在repository类上遇到以下错误:-

包含路径表达式必须引用导航属性 在类型上定义。使用虚线路径进行参考导航 属性和集合导航的选择运算符 财产


那么,我的代码有什么问题吗?

我想您可能需要执行以下操作

public AccountDefinition GetCustomer2(int id)
        {

            var c = entities.AccountDefinitions.Where(p=>p.ORG_ID==id)
                .Include(a => a.SDOrganization)
                .Include(a2 => a2.SiteDefinitions)
                .Include(a3 => a3.SDOrganization.AaaPostalAddresses)
                .Include(a4 => a4.SiteDefinitions.Select(a5 => a5.DepartmentDefinitions.Select(a6 => a6.SDUsers.Select(a7 => a7.AaaUser))));

            return c;
        }

感谢您的回复,但SDO组织没有。选择。如果我编写代码,我将得到以下错误:-“错误2'TMS.Models.SDOrganization'不包含'Select'的定义,并且找不到接受'TMS.Models.SDOrganization'类型的第一个参数的扩展方法'Select'(是否缺少using指令或程序集引用?)我明白了,那么问题可能是SelectMany,将SelectMany改为SelectMany。我被困在其他问题上,但你的答案告诉了我正确的答案direction@AtulChaudhary我也是,但这个解决方案有帮助。我想在根属性中包含一个虚拟属性集合。这是我的查询结果:返回this.Entities.Where(x=>x.Id==Id).Include(x=>x.QuestionSets).AsNoTracking().Include(x=>x.ProductTradeTypeMAPs.AsNoTracking().Include(x=>x.ProductTradeTypeMAPs.Select(y=>y.TradeType)).AsNoTracking().SingleOrDefault();