Search code examples
c#entity-frameworkasp.net-coreasp.net-core-scaffolding

.net core scaffold-dbcontext - 2 dbcontexts can't add duplicate table names


I have a .net core 3.1 application with 2 dbcontexts. Each points to their own, separate, databases. However, both databases have a couple of tables with the same name:

  • Database1 tables (Job and General)
  • Database2 tables (Job and General)

I have already added these tables for dbContext1:

Scaffold-DbContext "Server=ipaddress;Database=Database1;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Data -Tables "Job","General" -Context dbContext1

Now when I try to add these tables for dbContext2 it overwrites the entities created for dbContext1:

Scaffold-DbContext "Server=ipaddress;Database=Database2;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Data -Tables "Job","General" -Context dbContext2

How can i add the tables for dbContext2 without overwritting the entities created for dbContext1? Is it possible to alias?


Solution

  • I ended up using different namespaces: Saved entities for Database1 into Data_DB1 directory and entities for Database2 into Data_DB2 directory