Jack Corbett
Jack Corbett

Reputation: 40

Can I use the same Entity Model for 2 databases in one application

I have to create an application that will copy common configuration settings from one database to another database (same schema). I'm wondering if I can use one Entity Model to access both databases. Say it is stores and products that need to be copied. Can I use the same model to get a store from serverA.databaseA and then insert into server.databaseB?

Upvotes: 1

Views: 141

Answers (1)

Kamyar
Kamyar

Reputation: 18797

You can have two similar DbSets in two different DbContext classes. As mentioned in comments, the real problem is to deal with identity columns and IMO with context attachments. I think best way is to handle identity columns manually and fetch data from db in a detached state.

Upvotes: 1

Related Questions