0

I have seen a number of demos from 'respectable' individuals demonstrating the merits of the code first feature for Entity Framework. All of which looks like mouth watering toys!! but one thing strikes me...

Other than in development when would a code first scenario benefit my project?

Having the framework build the database for me seems awesome in a development and testing (portability!!!!) stage of the project but when I update the live project I would not want any of this to occur.

Knowing when the framework is about to overwrite my database and inserting my static data back in seems like a reasonable idea (for test scenarios) but all the demos I have seem put the code to construct this in the EF assembly.

EF Migrations is going to make this clear??? Maybe. Anyone have views on why I should be using this code first?

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
user634266
  • 95
  • 8

1 Answers1

0

In my opinion automatic database generation is only for development and testing. Once you move your application to a production environment you should make sure that this feature is turned off. This is especially important once you decide to deploy new version of your application.

EF Migration will perhaps change it by I'm sceptic. I would never let some automatic black box touching my production data. We already had very bad experience with VS Database tools so we never let them working with real data directly - we only let them generate script for us, we precisely test these script and manually execute these scripts on the production. Sometimes it even requires adding some additional migration scripts with temporary tables. That is exactly the approach which should be in my opinion used with EF as well. Let code first crate a new database in your dev environment, use a tool to create difference script for you against the old database, test it and deploy it.

But most importantly: Any upgrade or change on production database should start by backup so if tool fails you can always go back.

Choosing code first / database first / model first is based on the way how you like to develop application and on other requirements you have.

Community
  • 1
  • 1
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • The [new Migrations](http://blogs.msdn.com/b/adonet/archive/2012/01/12/ef-4-3-beta-1-automatic-migrations-walkthrough.aspx?CommentPosted=true#commentmessage) (beta) stuff looks very promising. It allows you to step up/down with automatic or custom changes and generate change scripts for hands-on production deployments (awesome!). – Michael Haren Feb 01 '12 at 13:55