Observation:
1. When two entity types have the same schema and table names by using TableAttribute, the Add-Migration generates the empty Up and Down methods, so that the Update-Database could run without problems.
2. When two entity types have the same schema and table names by using the Fluent APIs as follows, the Add-Migration generates the Up and Down methods that will cause the duplicate name errors by Update-Database.
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Post>().ToTable("Response", "NewSchema");
modelBuilder.Entity<Blog>().ToTable("BBS", "BrandNew");
}
Comments: You can set the same table name for different entities with either annotations or DbModelBuilder, but in either case, you can only do so when the entities are in the same type hierarchy. This is a supported scenario (TPH). Per yjhong's comment, it looks like in the annotations case he had wrong input to Add-Migration command. I have verified that in both cases, Up and Down methods of the migrations are created correctly to rename the table, hence closing this issue.
1. When two entity types have the same schema and table names by using TableAttribute, the Add-Migration generates the empty Up and Down methods, so that the Update-Database could run without problems.
2. When two entity types have the same schema and table names by using the Fluent APIs as follows, the Add-Migration generates the Up and Down methods that will cause the duplicate name errors by Update-Database.
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Post>().ToTable("Response", "NewSchema");
modelBuilder.Entity<Blog>().ToTable("BBS", "BrandNew");
}
Comments: You can set the same table name for different entities with either annotations or DbModelBuilder, but in either case, you can only do so when the entities are in the same type hierarchy. This is a supported scenario (TPH). Per yjhong's comment, it looks like in the annotations case he had wrong input to Add-Migration command. I have verified that in both cases, Up and Down methods of the migrations are created correctly to rename the table, hence closing this issue.