The Include path expression must refer to a navigation property defined on the type

ぐ巨炮叔叔 提交于 2019-11-30 14:35:45

问题


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:-

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.

So what is wrong with my code?


回答1:


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


来源:https://stackoverflow.com/questions/17596315/the-include-path-expression-must-refer-to-a-navigation-property-defined-on-the-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!