数据库迁移的实体框架4实体、框架、数据库

2023-09-02 20:49:13 作者:鸢尾

我一直在玩实体框架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在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> 。 A 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.