This question answers how to eager load the property of a derived class using include: Eager loading property of derived class using Include
This question answers how to load derived entity and object property of derived entity from a parent entity, but I believe it relies on lazy loading (please correct me if I'm wrong): Entity Framework - Eager loading of subclass related objects
My situation is similar to these, but I want to eager load properties on the derived entities from a parent entity when I have lazy loading explicitly disabled. Here is an example in the context of the other post:
Person
{
Name
Address
}
Employee : Person
{
Compensation - object
}
Visitor : Person
{
}
Company
{
ICollection<Person> People
}
In this example, I would want an expression to eager load Compensation objects when querying from the Company collection. My initial thought is to do something like this:
public IQueryable<Company> CompanyWithPeople() {
return Context.Company
.Include(c => c.People)
.Include(c => c.People.OfType<Employee>().Select(e => e.Compensation));
}
But that gives an error:
System.ArgumentException : The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties.
Is there any way to eager load the derived entity AND object properties of the derived class from a parent entity?