How to set the isolation level for Entity Framework CodeFirst Migrations

后端 未结 2 440
被撕碎了的回忆
被撕碎了的回忆 2020-12-28 17:59

If you run an entity framework migration (either automatic or explicit) against tables published for SQL Server replication you get the following error:

2条回答
  •  粉色の甜心
    2020-12-28 18:36

    Would it help to create your onw Migrator?

    internal sealed class Configuration : DbMigrationsConfiguration
    {
      public Configuration()
      {
        SetSqlGenerator("System.Data.SqlClient", new SqlMigrator());
      }
    
      private class SqlMigrator : SqlServerMigrationSqlGenerator
      {
        public override IEnumerable Generate(
          IEnumerable migrationOperations, string providerManifestToken)
        {
          yield return new MigrationStatement { Sql = "set transaction isolation level read committed" };
          foreach (var statement in base.Generate(migrationOperations, providerManifestToken))
            yield return statement;
        }
      }
    }
    

提交回复
热议问题