在实体框架中使用模型优先方法进行迁移 [英] Migration using model first approach in entity framework

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

问题描述

我已经建立了一个系统,在该系统中我采用了模型优先的方法,因为它对我来说更合乎逻辑.现在,即使我对模型进行了一些更改,目前我所做的也是 -

I have setup a system where I have taken the model first approach as it made more logical sense for me. Now when even I have some changes in the model currently what I do is -

  1. 使用实体框架的从模型生成数据库功能.我创建了一个虚拟数据库并应用了这些脚本.它首先删除我的所有数据和表,然后使用实体框架生成的最新 sql 文件更新数据库.
  2. 现在我使用 Visual Studio 的架构比较功能并为我的本地数据库和生产中的数据库生成迁移脚本.
  3. 我手动检查脚本并验证它们.完成后,我会在生产实例上运行迁移脚本.
  1. Use the Generate database from model feature of entity framework. I create a dummy database and apply those scripts. which deletes all my data and tables first and then updates the database with the latest sql file which is generated by entity framework.
  2. Now I use the Visual Studio's schema compare feature and generate migration scripts for my local database and also for the one which is in production.
  3. I go through the scripts manually and verify them. Once that is done I run the migration scripts on the production instances.

问题:主要问题是这真的很乏味,因为我是从本地系统完成的,所以连接到我的生产数据库非常慢,有时我的 Visual Studio 也会崩溃.有没有更清洁的方法来做到这一点?哪个自动化程度更高,以至于我的笔记本电脑并不真正负责生产实例上的数据库迁移?

Question : The main problem is that is really tedious and since I do it from my local system, connecting to my prod databases is very slow and sometimes my visual studio also crashes. Is there a more cleaner approach to do this? Which is more automated such that my laptop is not really responsible for the database migrations on the production instances?

推荐答案

你可以试试 Database Migration Power Pack - 它允许创建更改脚本而不是完整的数据库脚本,但在其后面执行与手动执行相同的过程.问题是提到了 工具不适用于 EF5.

You can try Database Migration Power Pack - it allows creating change scripts instead of full database scripts but on behind it does the same procedure as you did by hand. The problem is that mentioned tool will not work with EF5.

不幸的是 EF 迁移 目前不支持通过 EDMX 创建的模型.迁移目前仅支持代码优先方法.

Unfortunately EF migrations currently don't support models created through EDMX. Migrations support only code first approach at the moment.

这篇关于在实体框架中使用模型优先方法进行迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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