[ASP.NET Core 1.0] Automatic Migrations in Entity Framework 7 (EF Core 1.0)

By | January 31, 2016

Advertisement from Google

There is no more

public Configuration()
{
    AutomaticMigrationsEnabled = false;
}

in Entity Framework Core 1.0 (formerly  EF 7.0)

Now you can use extension Migrate method during database initialization.


Advertisement from Google

For example, you have custom DBInitializer class:

public class DBInitialization
{
    public static void Initialize()
    {
        using (var context = new DbContext())
        {
            context.Database.Migrate();
           
            // Other db initialization code.
        }
    }
}

There is also async version of this method. This method will apply any pending migrations.

You can call DBInitialization.Initialize at the end of Configure method at Startup class.

One thought on “[ASP.NET Core 1.0] Automatic Migrations in Entity Framework 7 (EF Core 1.0)

Leave a Reply

Your email address will not be published. Required fields are marked *