I have classes like:
Person
{
Name
Address
}
Employee : Person
{
Compensation - object
}
Visitor : Person
{
}
If I write linq:
var persons = Context.Persons
.Include("Compensation");
I get error:
A specified Include path is not valid. The EntityType 'Person' does not declare a navigation property with the name 'Compensation'.
It works ok if I do:
var persons = Context.Persons
.OfType<Employee>()
.Include("Compensation");
But I would like to get Employees and visitors in the same query.
Looks like there is a request for this feature on EF4 UserVoice: http://data.uservoice.com/forums/72025-ado-net-entity-framework-ef-feature-suggestions/suggestions/1249289-include-property-of-derived-classes?ref=title
but it does not look like it will get done any time soon.
What is a good workaround for this issue?