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

时间:2013-07-11 14:37:49

标签: 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)
            .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方法时,我在存储库类上得到以下错误: -

  

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

我的代码出了什么问题?

1 个答案:

答案 0 :(得分:29)

我想你可能想做类似

的事情
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;
        }