I have two classes SomeClass and SomeDerivedClass:
public abstract class SomeClass
{
int Id { get; set; }
public string BaseField { get; set; }
}
public class SomeOtherClass : SomeClass
{
public string SomeField { get; set; }
}
However, no matter what I try, Entity Framework tries to model the hierarchy in the database. I don't want SomeClass to be considered at all in the schema, I just want SomeOtherClass to act as its own entirely separate entity.
I want a single table called SomeOtherClass with columns Id, BaseField, and SomeField. However, Entity Framework always tries to create a table called SomeClass with a discriminator column, or one table for each.
List of things I have tried:
- Calling
.ToTable("SomeOtherClass")for both entities inOnModelCreating. Still adds a discriminator column. Tried addingHasNoDiscriminator(), but then I get the error
All the entity types in a hierarchy that don't have a discriminator must be mapped to different tables`
- Calling
.ToView(null)onSomeClassand.ToTable("SomeOtherClass")onSomeOtherClass. In this case the table loses the base columns (BaseField) - Calling
.HasBaseType<SomeClass>.HasBaseType<SomeOtherClass >on both, but then I get an error about invalid hierarchy. - Making the base class
abstractseems to have no effect.
How can I inherit a class in Entity Framework without it trying to make a hierarchy in the schema?