22

我有以下存储库方法:-

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 Method 时,我在存储库类上收到以下错误:-

包含路径表达式必须引用在类型上定义的导航属性。对引用导航属性使用虚线路径,对集合导航属性使用 Select 运算符。

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

4

1 回答 1

29

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;
        }
于 2013-07-11T15:27:24.660 回答