Entity Framework 6 Model First Migration

与世无争的帅哥 提交于 2019-12-18 12:24:27

问题


Desired outcome:

Use model first approach with Entity Framework and allow changes to deployed database/ model to be done automatically based on the changes in the model. Automatic schema difference script generation to allow smooth migrations.

Is there a way to perform migrations in model first EF6? I can see code first migrations topics all over, but nothing much on Model First.

Options I saw so far:

  • Database generation power pack (seems outdated)
  • somehow convert to code first, then use migrations (not desirable, as I like to have a visual designer)
  • somehow piggy back on code first migrations (http://blog.amusedia.com/2012/08/entity-framework-migration-with-model.html : this is for EF5, got error that can't run migrations on Model First)
  • some third party tools?

回答1:


As far as I know there still is no automatic migration for Entity framework model first.

Our approach is:

  1. Create a fresh database from the model.
  2. Create a diff script to migrate the old database to the new one.
  3. Verify that this diff script is indeed correct. Always double check what your automation tool creates.

We first used Open DB diff for our model first migrations. After that we switched to Redgate's SQL compare because it produced more reliable migrations . In our experience DbDiff produced a lot of unnecessary SQL because it bothers with the order that columns are in, and has some other issues like foreign keys constantly being dropped and re-added. Aside from that it still did the job fine, but we had to do a lot of double checking on its generated SQL.



来源:https://stackoverflow.com/questions/21393577/entity-framework-6-model-first-migration

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