In EF Core, I'm populating a navigation property ; User.BookMarks with Collection.LoadAsync:
public async override Task<User> Fetch(string id)
{
var user = await entities.FindAsync(id);
await context.Entry(user).Collection(i => i.BookMarks).LoadAsync();
return user;
}
However, BookMark also has a navigation property, BookMark.VgnItmEst which is not being populated. How do I populate that too?
Not obvious directly from the docs, but you can insert Query method (available for both collection and reference navigation properties) call which
Returns the query that would be used by
Load()to load entities referenced by this navigation property.
and apply as many Include / ThenInclude you want (similar to eager loading) before calling Load{Async}. e.g.
await context.Entry(user).Collection(i => i.BookMarks)
.Query()
.Include(e => e.VgnItmEst)
.LoadAsync();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With