How to migrate a database using Entity Framework 4.2?

I'm just starting to dive into ASP.net MVC3. I come from Django. One of the things I like about Django is the add-on called South. This allows me to modify my models in code, and then I run the command, it detects what has changed, and updates the database accordingly.

If I add, delete, or rename the "first code" field in EF4, what will happen? He just adds or removes the field and what is he? What if I want to do something like adding a new field, and then maybe run a Linq-to-SQL query to populate the new field, and then delete the old field? And I want to write this down so that when I start deploying the changes to my production server, it will run these 3 commands in sequence.

Is there something similar? Or how do people deal with such situations? (This is pretty common ...)


Edit: Find some links.

+4
source share
2 answers

Here's a great tutorial from Microsoft MVP David Hayden:
http://www.davidhayden.me/blog/asp.net-mvc-4-and-entity-framework-database-migrations

Not sure about 4.2 - but I installed the latest EF (4.3.1) and it worked like a charm.

Pretty impressive - and I'm a guy. Rails: P

+2
source

What happens depends on your initializations, I will discuss "standards" using network points.

Take a quick dive in:

Database Initialization Strategy - Look at the top, DropCreateDatabaseAlways is used here, so it will always delete the database and recreate it (you have other options). β€œIt says how EF should respond to database changes.”

Here are the possible database initialization

If you want Migration, there are two ways: - Magic - No-Magic

What you should know is that Migrations is actually 1 week (EF 4.2), it was implemented in EF 4.1, although not with full support (different DBs ...), but it is improving.

It depends on how much time you have, but I'm waiting to implement 4.2 and EF Migrations, I will implement it in a "test project" at the end of the week, see if everything is fine, and reply to the Ado.Net team blog ( see links to Magic - No-Magic). Although I do not think that there will be problems.

Best of luck of your choice :)

+2
source

Source: https://habr.com/ru/post/1379896/


All Articles