Entity Framework Migrations: Including Go statement only in -Script output

前端 未结 5 1738
暖寄归人
暖寄归人 2020-12-06 01:17

As part of planning an Entity Framework migration, in order to debug data movement, I would often use the -Script parameter to generate the script.

I could then take

5条回答
  •  旧巷少年郎
    2020-12-06 01:31

    This is working for me:

    public class MigrationScriptBuilder : SqlServerMigrationSqlGenerator
    {
        public override IEnumerable Generate(IEnumerable migrationOperations, string providerManifestToken)
        {
            var statements = base.Generate(migrationOperations, providerManifestToken);
    
            statements = statements.SelectMany(s => new[] {
                s,
                new MigrationStatement
                {
                    Sql = "GO"
                }
            }).ToList();
    
            return statements;
        }
    }
    

    Which (as seen in other answers) can be used (migration process flow) with this kind of method in the DbContext Configuration:

        public Configuration()
        {
            SetSqlGenerator("System.Data.SqlClient", new MigrationScriptBuilder());
        }
    

提交回复
热议问题