MS Entity Framework 4.1 - Maintain data across restructuring
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"?
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.
精彩评论