I am using Entity Framework 5.0 with a code approach and inheritance for my business objects represented by a table in a hierarchy.
I would like to have the following structure:
public class MyDbContext : DbContext
{
DbSet<AbstractClass> CommonObjects.AbstractClasses { get; set; }
}
public abstract class AbstractClass
{
}
public class DerivedClass : AbstractClass
{
}
At runtime, when trying to access DbContext for the first time, the compiler throws an InvalidOperationException saying:
The abstract type 'CommonObjects.AbstractClass' has no mapped children and therefore cannot be matched. Either remove the 'CommonObjects.AbstractClass' from the model or add one or more types derived from the 'CommonObjects.AbstractClass' to the model.
Is this scenario possible? If so, what am I doing wrong?
Thanks for your answers in advance.
Ben
Additional Information:
Maybe I should be more specific:
, - ( ). ( ) , . , persistance. EF , . , - - .
DbContext -.
:
AbstractClass derivedClass = new DerivedClass();
MyDbContext.AbstractClasses.Add(derivedClass);
. , .