Migration taking a lot of time to apply to the DB

76 Views Asked by At

I am working on an Entity framework project(code first) and got a situation to alter the table. I have run the add-migration for the same and got the migration file. when i try to apply this migration to the DB its taking a lot of time and I am getting a time out error in my application.

Here I am trying to alter columns(11 columns) to nullable for an existing table with 24379 records and few columns have existing values.

Is there any logic so that my application waits and the respective migration applies to my DB. I have increased the Transaction Timeout to 65535 seconds in the DB.Still the problem persists.

Any help?

Thanks in advance

1

There are 1 best solutions below

0
Steve Greene On

You need to use the commandtimeout:

internal sealed class Configuration : DbMigrationsConfiguration<ApplicationDbContext>
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = false;
        CommandTimeout = 300; // 5 minutes
    }
...
}

https://msdn.microsoft.com/en-us/library/system.data.entity.migrations.dbmigrationsconfiguration.commandtimeout(v=vs.113).aspx