Is it possible using DbContext / DbSet / DbQuery to conditionally eagerly load a navigation property. The query below will return parties that have a particular role.
What I need is to additionally only load the matching roles.
first attempt
var peopleWithRole = (from p in Party
from r in p.Roles
where r.RoleTypeId == 1
select p).Include(_ => _.Roles);
This loads all the roles, and it's obvious why once you look at it.
I have tried a few things. If I have to cast and create an objectquery to do it that would be fine, I just can't figure out how.
second attempt
var objectContext = ((IObjectContextAdapter)this).ObjectContext;
var set = objectContext.CreateObjectSet<Party>();
var result = (from p in set.Where("it.Roles.RoleTypeId == 1")
select p)
;
result.Dump();
The iterator cannot be used like this?
Any ideas?