Can you include more than just one relationship level using lambdas in linq to entities

StackOverflow https://stackoverflow.com/questions/23540980

  •  18-07-2023
  •  | 
  •  

문제

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?

도움이 되었습니까?

해결책

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))
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top