문제

I have this one-to-many and one-to-many relationship with entity framework and I had a hard time retrieving it using eager loading, this is the sample:

User has one to many relationship with Classmates which has one to many relationship with Items.

I'm trying to retrieve it as:

context.User.Include("Classmates").Include("Items").SingleOrDefault(n => n.username == "test");

But it issues and exception, I'am using entity framework 4.0 (ObjectContext). Thank you in advance guys!

Edit:

The exception is A specified Include path is not valid. The EntityType 'User' does not declare a navigation property with the name 'Items'.

도움이 되었습니까?

해결책

I've already found the answer here, sorry because I never heard of the term "Eager loading on multiple levels".

Here is the solution:

context.User.Include("Classmates.Items").SingleOrDefault(n => n.username == "test");

Here is the link for more articles regarding this problem:

http://msdn.microsoft.com/en-us/data/jj574232.aspx

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top