Supose I have following entities created from database tables:
Person
Student
Student include Person as navigation property.
Person has navigation property Country to connect lookup table Country.
In Student metadata, I do put [Include] for navigation property Person.
In Person metadata, I do put [Include] for navigation property Country.
When loading student data, I want to eager loading like to include Person and Country data:
this.ObjectContext.Students.Include("Person").Include("Country");
This was working fine when I use previous version of ASP.NET Data Ria Service. Now when it is changed to WCF Ria Service, above way not working any more.
System give me the error said Country is not a navigation property of Student.
How to resolve this problem?
The error is correct.
Includeis on theObjectQuery<T>you are querying, in this case “Students”.Countryis a navigational property ofPerson, notStudent.Change your code to this:
Or simply:
As EF will automatically include “Person” based on the nested include.
You need to remember that
Includereturns anObjectQuery<T>based on theObjectQuery<T>it was invoked upon.So just because your doing
Students.Include("Person"), that doesn’t mean at that point, the variable isObjectQuery<Person>– the variable is stillObjectQuery<Student>.