开发者

AutoMigration if the migration file exists

开发者 https://www.devze.com 2022-12-07 17:14 出处:网络
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.

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;
        }
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消