I have two entities in my project
Teacher which share a common base class,
AccountModel. The base class contains properties that are required by both students and teachers (semantically, both students and teachers are account holders, and for good practice, this prevents violation of the DRY principle)
In my Fluent API config I have:
builder .Ignore<AccountModel>(); builder .Entity<Student>() .HasBaseType<AccountModel>() .ToTable("Students"); builder .Entity<Teacher>() .HasBaseType<AccountModel>() .ToTable("Teachers");
But when EF scaffolds a migration and generates a new database, I get an
AccountModel table, but not a
Teachers table. What gives?
Currently, Entity Framework Core only supports the Table Per Hierarchy (TPH) pattern for mapping inheritance (http://www.learnentityframeworkcore.com/inheritance), which is why the migration results in one table for all types.