Scott
Scott

Reputation: 13931

Can the generated Entity Framework classes be used across multiple databases?

So I have multiple copies of the same database. Some of the tables are slightly different, but the ones I'm generating EF entities against are all identical. Does EF4 support making database calls against different databases just by swapping out the connection string or is it coupled somehow to the database it was generated against?

Upvotes: 0

Views: 257

Answers (1)

Youp Bernoulli
Youp Bernoulli

Reputation: 5655

You shouldn't have any pain by simply swapping the connectionstring assuming the databases are really identical. See it this way, the .edmx consists out of three parts:

  1. Entity definition
  2. Database definition and
  3. Mapping between these two.

Whether you use the entity model against db1 or db2 doesn't matter at all as long as one of those db's was used to generate the entity model and "db1=db2". The Sql that EF generates under the hood to communicate with the database is based entirely on the .edmx. So as long as your databases are identical expect no problems, they can be "reached" based upn the same .edmx! Try it yourself!

If you are really interested in EF and planning to use it, this (Programming Entity Framework by Julie Lerman) is a must read

Upvotes: 1

Related Questions