Entity Framework 6 模型优先迁移 [英] Entity Framework 6 Model First Migration

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

问题描述

期望的结果:

在实体框架中使用模型优先方法,并允许根据模型中的更改自动更改已部署的数据库/模型.自动生成架构差异脚本以实现平滑迁移.

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.

目前我看到的选项:

  • 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?

推荐答案

据我所知目前还没有自动迁移Entity framework model first.

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

我们的做法是:

  1. 从模型创建一个新的数据库.
  2. 创建差异脚本以将旧数据库迁移到新数据库.
  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.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆