I have a query below, but I want to perform an Include() to eager load properties. Actions has a navigation property, User (Action.User)
1) My basic query:
from a in Actions
join u in Users on a.UserId equals u.UserId
select a
2) First attempt:
from a in Actions.Include("User")
join u in Users on a.UserId equals u.UserId
select a
But Action.User is not populated.
3) Try to eager load 'User' into the navigation property in action outside of query:
(from a in Actions
join u in Users on a.UserId equals u.UserId
select a).Include("User")
In LINQPad trying Include's I get an error:
'System.Linq.IQueryable' does not contain a definition for 'Include' and no extension method 'Include' accepting a first argument of type 'System.Linq.IQueryable' could be found (press F4 to add a using directive or assembly reference)
I think this is because LINQ doesn't support Include().
So I tried in VS; query 2 runs, but returns unpopulated User property.
Query 3 the extension method does not seem to exist, although it does exist on Action itself without the query.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…