/// <inheritdoc /> protected override void Generate(CreateTableOperation operation, IModel model, MigrationCommandListBuilder builder) { if (!operation.IfNotExistsCheckRequired()) { base.Generate(operation, model, builder); return; } builder.AppendLine($"IF(OBJECT_ID('{DelimitIdentifier(operation.Name, operation.Schema)}') IS NULL)") .AppendLine("BEGIN"); using (builder.Indent()) { base.Generate(operation, model, builder, false); builder.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator); } builder.AppendLine("END") .EndCommand(); }
/// <inheritdoc /> protected override void Generate(CreateTableOperation operation, IModel model, MigrationCommandListBuilder builder, bool terminate = true) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (operation.IfExistsCheckRequired()) { throw new InvalidOperationException($"The check '{nameof(SqlServerOperationBuilderExtensions.IfExists)}()' is not allowed with '{operation.GetType().Name}'"); } if (!operation.IfNotExistsCheckRequired()) { base.Generate(operation, model, builder, terminate); return; } builder.AppendLine($"IF(OBJECT_ID('{DelimitIdentifier(operation.Name, operation.Schema)}') IS NULL)") .AppendLine("BEGIN"); var unterminatingBuilder = new UnterminatingMigrationCommandListBuilder(builder, Dependencies); using (builder.Indent()) { base.Generate(operation, model, unterminatingBuilder, false); builder.AppendLine(Dependencies.SqlGenerationHelper.StatementTerminator); } builder.AppendLine("END"); if (terminate || unterminatingBuilder.SuppressTransaction.HasValue) { builder.EndCommand(unterminatingBuilder.SuppressTransaction ?? false); } }