Question

I have a data structure in which Users have UserPlans and UserPlans have Plans. I've included a using statement for System.Data.Entity so that I can strongly type my includes, but I can't figure out if there's a way to strongly type an include that goes more than one level deep in the relationships. So I have:

from user in entities.Users.Include(u => u.UserPlans).Include("UserPlans.Plans")

but I'd like to be able to do something like:

from user in entities.Users.Include(u => u.UserPlans).Include(u => u.UserPlans.Include(up => up.Plan))

In order not to have the string in my include. Is there a way to do so?

Was it helpful?

Solution

Looks like this has been answered before: EF CTP5 - Strongly-Typed Eager Loading - How to Include Nested Navigational Properties?

Basically:

from user in entities.Users.Include(u => u.UserPlans.Select(p => p.Plans))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top