I have a database that was created with the Entity Framework’s code first approach.
Currently it has just 5 tables. One of the tables, called Incidents, backs the Incident C# class. The class needs to get just one additional property – bool HasClaim.
I know that since the DB is initialized with DropCreateDatabaseWhenModelChanges, the moment I will try to initialize with an adjusted entity class, my DB data will get purged, and a new database will be created.
What is the simplest path for me to make this class/schema update? (in general, like: read data into an XML, recreate DB and manually, from C# code, place new entities.)
P.S.
Maybe I can go ahead and create a Database model from current DB, adjust it, adjust the code, and reconfig to no longer use code-first? I seems like code-first currently is only good if you are 100% sure you are not to change the models after the DB goes into production. But with a successful projects, it is never the case!
Have a look at Entity Framework Migrations:
http://blogs.msdn.com/b/adonet/archive/2012/01/12/ef-4-3-beta-1-automatic-migrations-walkthrough.aspx
Another approach is to only have the DropCreateDatabaseWhenModelChanges strategy in debug builds (for test environments) and then scripting schema changes with another tool for upgrading production environments.