实体框架的数据库迁移4 [英] Database migrations for Entity Framework 4

查看:125
本文介绍了实体框架的数据库迁移4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在玩实体框架4,使用模型驱动的方法从我的实体生成数据库脚本。这是伟大的,但我不知道如何工作,当涉及到版本控制数据库。我猜,如果我想使用一个活跃的记录类型迁移框架,我必须以其他方式工作,并从我的数据库生成我的实体?有没有办法使用模型驱动的方法并正确地版本数据库?

I've been playing with Entity Framework 4, using the model driven approach to generate the database script from my entities. This is great but I'm not sure how this works when it comes to versioning the database. I'm guessing if I wanted to use an active record type migration framework I'd have to work the other way around and generate my entities from my database? Is there any way to use the model driven approach and version the database properly?

推荐答案

这将是即将推出的NuGet软件包称为EntityFramework.Migrations

This will be coming soon as a NuGet package called EntityFramework.Migrations

演示由Scott Hanselman在TechEd 2011上执行(可从 http://channel9.msdn.com/Events/TechEd/NorthAmerica/2011/DEV349 )。相关部分是45分钟。

A demo was performed by Scott Hanselman at TechEd 2011 (available online at http://channel9.msdn.com/Events/TechEd/NorthAmerica/2011/DEV349). The relevant section is 45 minutes in.

简而言之,一旦安装了软件包,您将在包管理器控制台中输入以下内容,以生成数据库更改脚本:

In short, once the package is installed, you'll enter the following into the Package Manager Console to generate a database change script:

migrate -script

更新(2011年11月13日)

这个包的alpha 3版本现在在NuGet上可用。而不是使用上面提到的cmdlet migrate -script ,它使用cmdlet Add-Migration< migrationname> 。 A

The alpha 3 build of this package is now available on NuGet. Rather than use the cmdlet migrate -script mentioned above, it uses the cmdlet Add-Migration <migrationname>. A walk-through of its use can be found on the ADO.NET team blog.

更新(2012年2月14日)

UPDATE (14-Feb-2012)

此功能现在可作为主要 EntityFramework NuGet软件包,从版本4.3开始。可以在ADO.NET团队博客中找到使用EF 4.3的更新的步态

This functionality is now available as part of the main EntityFramework NuGet package, starting with version 4.3. An updated walk-through using EF 4.3 can be found on the ADO.NET team blog.

这篇关于实体框架的数据库迁移4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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