简体   繁体   中英

Entity Framework Update Database On Model Change

I am currently using auto-migrations with the following powershell console commands: add-migration update-database

I would like to know if there is an option to update the database automatically if the model changes (DbContext) without using the console commands.

Thanks.

I use

public class DataContext : DbContext
{

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {

        Database.SetInitializer(new MigrateDatabaseToLatestVersion<DataContext,Configuration>());

        base.OnModelCreating(modelBuilder);
    }
}

This causes the database migrations to the latest version when the data context is created at code runtime.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM