Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migration using model first approach in entity framework

I have setup a system where I have taken the model first approach as it made more logical sense for me. Now when even I have some changes in the model currently what I do is -

  1. Use the Generate database from model feature of entity framework. I create a dummy database and apply those scripts. which deletes all my data and tables first and then updates the database with the latest sql file which is generated by entity framework.
  2. Now I use the Visual Studio's schema compare feature and generate migration scripts for my local database and also for the one which is in production.
  3. I go through the scripts manually and verify them. Once that is done I run the migration scripts on the production instances.

Question : The main problem is that is really tedious and since I do it from my local system, connecting to my prod databases is very slow and sometimes my visual studio also crashes. Is there a more cleaner approach to do this? Which is more automated such that my laptop is not really responsible for the database migrations on the production instances?

like image 731
tusharmath Avatar asked Aug 12 '12 07:08

tusharmath


People also ask

How do you do migration in db first approach?

To do this, Suppose that you have the following DbContext that EF Db first created for you: public class MyDbContext : DbContext { public MyDbContext() : base("Name=DefaultConnection") { } // DbSets ... } change that to the following to start using code first and all magic tools of it (migration, etc.):

How do I use migration in Entity Framework?

The EF command-line tools can be used to apply migrations to a database. While productive for local development and testing of migrations, this approach isn't ideal for managing production databases: The SQL commands are applied directly by the tool, without giving the developer a chance to inspect or modify them.


1 Answers

You can try Database Migration Power Pack - it allows creating change scripts instead of full database scripts but on behind it does the same procedure as you did by hand. The problem is that mentioned tool will not work with EF5.

Unfortunately EF migrations currently don't support models created through EDMX. Migrations support only code first approach at the moment.

like image 131
Ladislav Mrnka Avatar answered Sep 18 '22 05:09

Ladislav Mrnka