By default, EF6 would map a base abstract class and it's derived classes for Table Per Hierarchy (TPH).
EF Core no longer follows this logic and requires derived classes to be opted in. The documentation states:
By convention, types that are exposed in DbSet properties on your context are included in the model as entities. Entity types that are specified in the OnModelCreating method are also included, as are any types that are found by recursively exploring the navigation properties of other discovered entity types.
Using this approach is not too hard to follow if you have a few sub-types as you can just add them as DbSets or add a HasDiscriminator().HasValue() for each sub-type with mapping as below:
builder.HasDiscriminator()
.HasValue<CommaSymbolRule>("CommaSymbolRule")
.HasValue<DashSymbolRule>("DashSymbolRule")
.HasValue<IsNumericSymbolRule>("IsNumericSymbolRule")
.HasValue<IsPunctuationSymbolRule>("IsPunctuationSymbolRule")
.HasValue<PeriodSymbolRule>("PeriodSymbolRule")
In some circumstances this is a sub-optimal as you may have many derived classes. In my case, I have a rules engine and do not want to have map each rule individually.
Is there a way to automatically map the sub-types of a base class in an EF Core Table Per Hierarchy scenario without having to manually add them?