AutoMigration if the migration file exists
In my project I am working on, my database is created as code first. When I run the project after making any changes to the Entity class, it automatically detects the change and updates the database.
But instead, if I have created a migration file with "Add-Migration {changeName}" I want it to update it while the project is up. So I'll just create the file by saying add-migration and the project will perform the update-database phase if the file exists while it is standing up.
How can I handle this?
I am using .Net Framework 4.8.
My DbContext class:
public ApplicationDbContext()
: base("DefaultConnection")
{
Database.SetInitializer(new MigrateDatabaseToLatestVersion<ApplicationDbContext, MigrationsConfiguration>("DefaultConnection"));
Database.CommandTimeout 开发者_高级运维= 60;
}
My Migration Configuration Class:
internal sealed class MigrationsConfiguration : DbMigrationsConfiguration<ApplicationDbContext>
{
public MigrationsConfiguration()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = true;
CommandTimeout = 60 * 10;
}
}
精彩评论