public void AddDefaultConstraintBatches(IEnumerable <Table> tables, QuoteType quoteType = QuoteType.NotQuoted) { var definitions = new List <TableDefaultConstraint>(); AddBatch(Generator.GeneratePrintStatement($"========== Creating Default Constraints ==========")); foreach (Table table in tables) { foreach (var column in table.Columns) { if (!string.IsNullOrEmpty(column.DefaultName)) { definitions.Add(new TableDefaultConstraint { Constraint = ScriptFactory.DefaultConstraintDefinition( ScriptFactory.Identifier(column.Name, quoteType), ScriptFactory.Identifier(column.DefaultName, quoteType), false, ScriptFactory.ParenthesisExpression(ScriptFactory.IntegerLiteral(column.DefaultValue))), Table = table }); } } } AddDefaultConstraints(definitions, quoteType); }
public static ColumnDefinition Column2(string columnName, string defaultValue, string defaultName, DataTypeReference dataType, bool nullable = false, bool isRowGuid = false, QuoteType quoteType = QuoteType.NotQuoted) { var fragment = new ColumnDefinition(); fragment.Constraints.Add(ScriptFactory.NullableConstraintDefinition(null, nullable)); fragment.Constraints.Add(ScriptFactory.DefaultConstraintDefinition( null, ScriptFactory.Identifier(defaultName, quoteType), false, ScriptFactory.IdentifierLiteral(defaultValue))); fragment.ColumnIdentifier = ScriptFactory.Identifier(columnName, quoteType); fragment.IsRowGuidCol = isRowGuid; fragment.DataType = dataType; return(fragment); }