Is there a way to tamper with the DbContext in order to auto eager load a specific Navigation property when the entity is requested in a query? (no lazy loading).
Entity Framework 5
Example:
var supremeEmployee = context.Employees.FirstOrDefault(x => x.EmployeeId == 42);
and the returned model would come back pre-populated with the “Department” navigation property.
Depends on what your model looks like. If you’re using interfaces or inheritance you could add a function to your DbContext class with a generic constraint on that type that always includes the navigation property.
In my experience though you’re usually better off not doing that, performance wise. I prefer to load into anonymous types just the fields i need in the moment.
In the most basic way you could do this: