Reputation: 271
I want to use Code First Technique of EF6 but when i made changes to table, it drops the database and recreates it, wiping out all data. Is there any way to stop this from happening?
My Code :
Database.SetInitializer<EmployeeDb>(new DropCreateDatabaseIfModelChanges<EmployeeDb>());
Upvotes: 0
Views: 961
Reputation: 916
These are the strategies for database initilization in code first approach:
Here, it can give you general idea and how to use one of these approaches.
Due to your comments CreateDatabaseIfNotExists
helps you. With this approach when you add or remove your model classes, your db
will be updated and your data will be stable.
Here you can find examples both Context
constructor and config
file
Another topic about this on stackoverflow.
Upvotes: 1