0

I am using the Code First approach to manage the EF. However all the examples I have seen don't seem to allow you to use EF where you are able to make changes to the DB schema and preserve your data.

So say I have an entity/object of:

public class Person
   int Id;
   string NickName;

and I now add Age so:

public class Person
   int Id;
   string NickName; 
   int Age;

how can I preserve the data that may already be in the database for "Person"?

TheEdge
  • 9,291
  • 15
  • 67
  • 135
  • possible duplicate of http://stackoverflow.com/questions/6720363/entity-framework-4-1-custom-database-initializer-strategy – Eranga Jul 21 '11 at 04:40
  • possible duplicate of [Entity Framework 4.1 - Tracking and manually deploying DDL changes using T-SQL.](http://stackoverflow.com/questions/6753064/entity-framework-4-1-tracking-and-manually-deploying-ddl-changes-using-t-sql) – Ladislav Mrnka Jul 21 '11 at 07:25

1 Answers1

-1

Dont call the System.Data.Entity.Database.SetInitializer().

Or call System.Data.Entity.Database.SetInitializer() with CreateDatabaseIfNotExists().

Calling with DropCreateDatabaseAlways or DropCreateDatabaseIfModelChanges will always drop Db.

ozczecho
  • 8,649
  • 8
  • 36
  • 42
  • I dont agree. I have given TheEdge some options. Sure I could have added one more (ie implement IDatabaseInitializer urself) but the above answers the question. – ozczecho Jul 21 '11 at 04:44
  • hes asking for a solution and you are answering with bunch of `Don't`s. The `Do`s part is missing in your answer :) – Eranga Jul 21 '11 at 04:56