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

问题描述:

我具有以下存储库方法:-

I have the following Repository method:-

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

以下调用上面方法的操作方法:-

The the following action method which calls the above method:-

public ActionResult Details2(int id = 0)
{
    AccountDefinition cd = repository.GetCustomer2(id);
    return View("copy",cd);
}

但是当我导航到操作方法"时,在存储库类上出现以下错误:-

but when i navigate to the Action Method , i get the following error on the repository class:-

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

The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties.

那我的代码怎么了?

我认为您可能想做类似的事情

I think you may want to do something like

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