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

查看:157
本文介绍了数据库迁移的实体框架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在<一个执行在2011微软技术大会(可在网上href="http://channel9.msdn.com/Events/TechEd/NorthAmerica/2011/DEV349">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

更新(11月13日 - 2011)

的Alpha 3版本这个包是现在可以在的NuGet。而不是使用该cmdlet 迁移-script 上面提到的,它使用的cmdlet的添加-迁移与LT; migrationname&GT; 。 A <一个href="http://blogs.msdn.com/b/adonet/archive/2011/09/21/$c$c-first-migrations-alpha-3-no-magic-walkthrough.aspx">walk-through其采用可以在ADO.NET团队博客上找到。

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.

更新(14月 - 2012)

这个功能现在可以通过主的EntityFramework的NuGet包的一部分,从4.3版。一个更新步行通过使用EF 4.3可以在ADO.NET团队博客上找到。

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天全站免登陆