实体框架6模型优先迁移

编程入门 行业动态 更新时间:2024-10-25 06:23:43
本文介绍了实体框架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:

  • 数据库生成电源包(似乎已过时)
  • 以某种方式先转换为代码,然后使用迁移(这并不理想,因为我希望有一个视觉设计师)
  • 以某种方式piggy带代码优先迁移( http: //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?
推荐答案

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

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

我们的方法是:

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

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

    发布评论

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

    >www.elefans.com

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