实体框架6模型优先迁移

实体框架6模型优先迁移

本文介绍了实体框架6模型优先迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所需结果:

将模型优先方法与Entity Framework结合使用,并允许根据模型中的更改自动完成对已部署数据库/模型的更改.自动生成模式差异脚本,以实现平稳的迁移.

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.

是否有一种方法可以在模型优先EF6中执行迁移?我可以看到遍及代码优先的迁移主题,但是在Model First上却没什么.

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?

推荐答案

据我所知,仍然没有针对实体框架模型的自动迁移.

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

我们的方法是:

  1. 从模型创建一个新的数据库.
  2. 创建一个diff脚本,将旧数据库迁移到新数据库.
  3. 验证此差异脚本确实正确. 始终仔细检查自动化工具创建的内容.

我们首先将 Open DB diff 用于我们的模型首次迁移.之后,我们切换到 Redgate的SQL比较,因为它产生了更可靠的迁移.根据我们的经验,DbDiff产生了许多不必要的SQL,因为它困扰着列的顺序,并且还存在其他一些问题,例如不断删除和重新添加外键.除此之外,它仍然可以很好地完成工作,但是我们必须对其生成的SQL进行很多重复检查.

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.

这篇关于实体框架6模型优先迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 15:02