EF6 seed without database update

I have an application configured right now to use EF6 Code-First Migrations. I use the standard Add-Migration workflow and then the updated database in the console. I use the MigrateDatabaseToLatestVersion initializer locally as well as in our development environment. This automatically handles all migrations for me and other developers.

It’s inconvenient for me to allow automatic migrations during production, so I ran Update-Database - a script to create an SQL Script that I could preview before running. This works very well, and I'm fine with this process for deployments. However, I realized that the SEED method will never be launched, because Update-Database does not work directly in the database.

I am looking for a good way to get the SEED method in a migration configuration to run without actual migrations. I found migrate.exe ( http://msdn.microsoft.com/en-us/data/jj618307.aspx ) that looks like it might work, but I wanted to see if anyone knows the best ways.

Also, and perhaps more importantly, I'm ridiculously worried about Auto-Migration in production, given how much automation I already use with EF6 ??

Thank!

+4
source share
2 answers

FYI - , - , . "". DatabaseInitializer, web.config. MigrateToLatestVersion Dev , .

public class SeedOnlyInitializer : IDatabaseInitializer<YourContextType>  {

    public void InitializeDatabase(YourContextType context)
    {
        Seed.Execute(context);
        context.SaveChanges();
    } 
}

, . , , .

+2

, :

  • update-database -script ( )
  • SQL script ( )
  • update-database ( -script ). SQL script, , Configuration::Seed().
-1

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


All Articles