Keep Database Content On Model Change

主宰稳场 提交于 2019-12-21 05:04:58

问题


Using the code-first approach available in the new 4.1 RC.

Is there any way to persist the current data stored in a database when the mode changes? The database is created by the entity framework, and usually the database is dropped and recreated on model changes.

Obviously as soon as the model is changed it will not be possible to use the context object to connect to the database to retrieve the data, so what are the options?


回答1:


Code first doesn't support database migration / evolution yet. If you want to do incremental DB development use model first (EDMX) with DbContext Generator T4 template and Entity designer database generation pack which is able to create diff. scripts from the model.




回答2:


From Scott Gu:

Importantly, though, the auto-create database option is just an option – it is definitely not required. If you point your connection-string at an existing database then EF “code first” will not try and create one automatically. The auto-recreate option also won’t be enabled unless you explicitly want EF to do this – so you don’t need to worry about it dropping and recreating your database unless you’ve explicitly indicated you want it to do so.



来源:https://stackoverflow.com/questions/5463121/keep-database-content-on-model-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!