I have a program using C# / WPF and SQL Server with EF Core 5. Sometimes I use eager loading, for example:
(from r in MyContext.Refractions where r.Id == id select r)
.Include(r => r.RightLens)
.ThenInclude(l => l.Prisms);
and so on. This is a database of optical data, hence the field names. Refractions are linked to (eye) Examinations.
When I want to lazy load, I use the following:
MyContext.Entry(patient)
.Collection(e => e.Examinations).Load();
My question is, when using the second, lazy option, is there a way to also load associated data (the equivalent of .Include for the Load method)?
So for example, I want the equivalent of:
MyContext.Entry(patient)
.Collection(e => e.Examinations)
.Load().Include(r => r.Refractions);
or do I need to detect that the Refractions collection is not loaded somewhere in my view model and then load it manually when required?
virtuallearn.microsoft.com/en-us/ef/core/querying/related-data/…