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

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

问题描述

我设置了一个系统,我采取模型第一种方法,因为它对我更合乎逻辑的意义。现在,即使我在模型中有一些变化,我现在做的是 -

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.

问题:主要问题是这是非常乏味,因为我从我的本地系统,连接到我的prod数据库是非常缓慢,有时我的视觉工作室也崩溃。有更清洁的方法吗?这是更自动化,我的笔记本电脑不是真正负责数据库迁移的生产实例?

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?

推荐答案

a href =http://visualstudiogallery.msdn.microsoft.com/df3541c3-d833-4b65-b942-989e7ec74c87/ =noreferrer>数据库迁移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天全站免登陆