Entity Framework 6 模型优先迁移

编程入门 行业动态 更新时间:2024-10-26 15:16:44
本文介绍了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.

目前我看到的选项:

  • 数据库生成电源组(似乎已过时)
  • 先以某种方式转换为代码,然后使用迁移(不可取,因为我喜欢有视觉设计师)
  • 以某种方式搭载代码优先迁移(blog.amusedia/2012/08/entity-framework-migration-with-model.html:这是针对 EF5,出现无法在 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 (blog.amusedia/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.

我们的做法是:

  • 从模型创建一个新的数据库.
  • 创建差异脚本以将旧数据库迁移到新数据库.
  • 验证此差异脚本确实正确.始终仔细检查您的自动化工具创建的内容.
  • 我们首先使用 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 模型优先迁移

    本文发布于:2023-11-15 12:35:07,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1594492.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:模型   Entity   Framework

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!