Create a migration operation inside a custom migrations operations

80 Views Asked by At

I am using a custom migration operation in order to update the schema for all tables in the model, e.g.

    private void Generate(CreateUserOperation operation, MigrationCommandListBuilder builder)
    {
        var sqlHelper = Dependencies.SqlGenerationHelper;
        var stringMapping = Dependencies.TypeMappingSource.FindMapping(typeof(string));

        foreach (var entityType in model.GetEntityTypes())
        {
            builder
                .Append("ALTER TABLE ")
                .Append(sqlHelper.DelimitIdentifier(entityType.GetTableName()))
                .Append("ADD COLUMN ")
                .Append(sqlHelper.DelimitIdentifier("TheNewColumn"))
                .Append(" TEXT")
                .AppendLine(sqlHelper.StatementTerminator)
                .AppendLine()
                .EndCommand();
        }
    }

Of course this would be much easyier if I could use the existing AddColumnOperation . Is there a way to achive this?

0

There are 0 best solutions below