Open omuleanu opened 3 years ago
@smitpatel FYI
For explicit loading you would need to load each navigation individually. So make similar call for each navigation with Reference/Collection API. This will cause 1 database round-trip for each loaded navigation.
If you want to load multiple navigations in single database round-trip then it is not really explicit loading, it is eager loading (load navigation(s) when querying from database).
You can write query to do so like this.
await context.EntitySets.Where(e => e == ent).Include(...).LoadAsync()
This will avoid multiple database round-trip at the expense of fetching data for entity from server again. The entity entry in client side won't change since EF Core doesn't materialize entity from database if entity with same key is already being tracked. It just re-used already tracked instance.
If you want to remove trade-off of both above (multiple roundtrips vs fetching additional data), then you would need to write a query manually which fetches data for related navigations and mark navigations loaded explicitly in entity entry.
@smitpatel I ended up using DbSet.Where(...).Include(...).Include(...)
what I was trying to say is that the documentation doesn't specify what to do when you want to load more than one property
cc: @roji
Yeah, we could add a note about this.
this works:
await context.Entry(ent).Reference(o => o.Prop1).LoadAsync();
but how do you load multiple properties, you can't chain multiple.Reference
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.