3

So I have been working on a project using Entity Framework 5 in development for a while and it is decided that the code will need to be moved to a production environment.

My question is what would be a good approach to do this?

My initial thought is to have two edmx files in my project and then comment out the production connection string in my development environment and vice-versa in the production environment. However that doesn't seem feasible as I cannot have two entity model with the same name in the connection string, thus resulting in changing the model "context" instance throughout my code which doesn't make sense.

Another thought that I had was just to modify the connection string of the model used by the development database to point to the production datasource (since they both have same table structure). But I don't know if I will break anything here.

I have looked at this post here and it didn't help: Entity framework working with both production and development database

Note: I am not using the code first pattern but generating the model from the database and that both the development and production database have syncing database structure.

Thanks!

Community
  • 1
  • 1
Steven
  • 974
  • 6
  • 18

2 Answers2

5

You can use transformations in your web.config file to automatically switch which database you are referencing.

Check out this similar answer: Web.Config Debug/Release

Community
  • 1
  • 1
Brandon
  • 983
  • 6
  • 15
  • Yeah transforms are the way to go, if you have anything more exotic than the normal web.config look at [SlowCheetah](http://visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5) which does transforms for other XML files. – Jafin Apr 10 '14 at 08:05
1

You still have the connection string in your web.config (yeah, big, long Entity connection string, but it's there). Just make sure the connection string in your production deployment points to the production database server. I would suggest using config transforms:

http://msdn.microsoft.com/en-us/library/dd465326.aspx

Gromer
  • 9,861
  • 4
  • 34
  • 55