Changing your configuration to Table Per Type should give the tables you expect. More details of how table per type generates tables are located here.
EF doesn't Create my table
-
24-06-2023 - |
Question
I have three class, using TPH(table per hiracy):
abstract class Cat { int Id; string Name; }
class ItemCat: Cat { }
class PhotoCat: Cat{ }
and
class Db:DbContext
{
Db()
{
Database.SetInitializer(new MigrateDatabaseToLatestVersion<Db,Migrations.Configuration>());
}
DbSet<ItemCat> ItemCats;
DbSet<PhotoCat> PhotoCats;
}
and also have Seed() method to seed ItemCats
update-database run well and seed table.
But EF doesn't create my ItemCat! and insteed it create Cats! & seed it. i don't have cats in DbContext.
I also add [Table("ItemCats")] to ItemCat class, ItemCats table appear but just have id column in it!!
I think it's because ItemCat & PhotoCat classes are empty & just inherit from Cat class. it's strange for me.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow