I am attempting to deploy my first alpha version of a system online for a few people to start using. On development I make heavy use of the DropCreateDatabaseOnModelChange<TContext> (I don’t have it in front of me at the moment so I can’t verify the exact name) to re-initialize my dev database every time my model changes. This happens in the Global.asax.
However, I do not want this to happen on my web host where other people are entering real data. I need to handle all db migrations on there myself so data is preserved.
I had considered #ifdef DEBUG tags to prevent the database initializer from being called, but I don’t like that solution. Right now, I have the debug version deployed, so if they come across any errors it is easy for me to see and debug them (this is very very alpha, so only a select few people are using it and know to expect errors).
What other options do I have to prevent Prod DB dropping by EF4 code first?
You can always create a new Configuration (in addition to Debug and Release). You would then define a Conditional Compilation Symbol for the new configuration. For example if I created a new configuration called LocalDebug (with the same settings at the default debug) I would then add LOCALDEBUG to the Conditional Compilation Symbols. With this defined you can use:
Then you can still deploy the built in debug configuration and this section will not fire.