Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database migrations for Entity Framework 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?

like image 992
Charlie Avatar asked Feb 04 '10 09:02

Charlie


People also ask

What is database migration in Entity Framework?

The migrations feature in EF Core provides a way to incrementally update the database schema to keep it in sync with the application's data model while preserving existing data in the database.

How do I use migrations in Entity Framework?

Step 1 − Before running the application you need to enable migration. Step 2 − Open Package Manager Console from Tools → NuGet Package Manger → Package Manger Console. Step 3 − Migration is already enabled, now add migration in your application by executing the following command.

How do I enable-migrations in Entity Framework Core?

Migrations are enabled by default in EF Core. They are managed by executing commands. If you have Visual Studio, you can use the Package Manager Console (PMC) to manage migrations. Alternatively, you can use a command line tool to execute Entity Framework CLI commands to create a migration.


2 Answers

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

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

UPDATE (13-Nov-2011)

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.

UPDATE (14-Feb-2012)

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.

like image 136
Richard Fawcett Avatar answered Oct 04 '22 08:10

Richard Fawcett


You can try Wizardby: this is a tool for managing database migrations. It doesn't integrate with EF (since it's nearly impossible to integrate with it in this respect), but does the job.

like image 22
Anton Gogolev Avatar answered Oct 04 '22 08:10

Anton Gogolev