Search code examples
entity-frameworklinq-to-sqlentity-framework-4linq-to-entitiesnavigation-properties

Having Multiple level of Navigation properties in entity framework Fails


I have following query in my code:

var query3 = (from b in context.SystemDetails.Include("UserHousing").Include("UserInfo") where (b.UserHousing.UserInfo.FullName.StartsWith("Far")) select b).ToList();

Why does it give error that systemDeail do not have navigation property "UserInfo" .. it should not matter as UserHousing Have that Navigation property...


Solution

  • You should specify the correct path to UserInfo:

    context.SystemDetails.Include("UserHousing.UserInfo")
    

    Or

    context.SystemDetails.Include(x => x.UserHousing.UserInfo)