Its clear to me that I can customize the behavior of syncing models and DB schema process. I am using the DropCreateDatabaseIfModelChanges<> class to do so.
Assume that I have a working project and site and DB is filling in the data. Everything is working fine.
One day I decide that some functionality needs to be changed. The changes will affect the properties of my models (they can be renamed/deleted/added, some models will be new, some models are deleted).
My question: What will happen with the already existing data on my deployed site when I check in all of my changes?
Will I lose it? If so, how can I avoid that?
Yes, you will lose your data if your model changes and you are using
DropCreateDatabaseIfModelChanges<T>To avoid this:
Don’t use Db initializers in production (maybe except the
CreateDatabaseIfNotExists<T>). DB initializes are there to smooth the development experience, not for production use.What you need is the new Migration feature of Entity Framework 4.3. (currently in Beta1) which provides features for automatic and code base db schema migration.
Also now you can set the DB initializer from the
*.configfile, so you can easily switch beetween the development timeDropCreateDatabaseIfModelChangesto no initializer in production configurations.