I am trying to use inherited types with EF, which has been all cool and gravy until now.
I have a base type (Person) and two types that inherit person (Employee & Customer). I run into a problem when I want a person to be an Employee and a Customer at the same time. For example:
Person person = db.Persons.Single(p => p.id == id);
if (person is Employee)
{
Console.WriteLine("Person is an employee");
}
//True only if person is Employee == false
if (person is Customer)
{
Console.WriteLine("Person is a customer");
}
If I map a Person to an Employee and a Customer, “Person is Customer” always returns false until I remove the Employee mapping from the person.
And I am not sure what that is called… but there is a table per type (Person is a table, Customer is a table, and Employee is a table in the DB).
You can’t do this since you can not have multiple inheritance.
Within your DB Customer and Employee tables I would suggest foriegn key into the Person table. Then in your object model the Customer and Employee there would be a Person property.
As you are just wanting to iterate over whether they are Customers or Employee’s just use linq on those collections which should be on the Entity context