Вопрос

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