示例#1
0
        public IEnumerable <string> ToSql(IProvider provider, IMigrationContext context)
        {
            if (IsNullable && DefaultValue != null)
            {
                throw new InvalidCommandException("Adding nullable columns with default values is not supported: some database platforms (like SQL Server) leave missing values NULL and some update missing values to the default value. Consider adding the column first as not-nullable, and then altering it to nullable.");
            }
            TableName            tableName = new TableName(Parent.TableName, Parent.Schema ?? context.GetDefaultSchema());
            var                  dataType  = new DataType(Type, Size, Scale);
            var                  column    = new Column(ColumnName, dataType, IsNullable, DefaultValue, IsRowVersion);
            IEnumerable <string> commands  = provider.AddColumn(tableName, column);

            if (DropThereafter)
            {
                commands = commands.Concat(provider.DropDefault(tableName, new Column(
                                                                    column.Name,
                                                                    column.DataType,
                                                                    column.IsNullable,
                                                                    null, false)));
            }
            return(commands);
        }
示例#2
0
 public IEnumerable<string> ToSql(IProvider provider, IRuntimeContext context)
 {
     if (IsNullable && DefaultValue != null)
     {
         throw new InvalidCommandException("Adding nullable columns with default values is not supported: some database platforms (like SQL Server) leave missing values NULL and some update missing values to the default value. Consider adding the column first as not-nullable, and then altering it to nullable.");
     }
     string tableName = Parent.TableName;
     var dataType = new DataType(Type, Size, Scale);
     var column = new Column(ColumnName, dataType, IsNullable, DefaultValue, IsRowVersion);
     IEnumerable<string> commands = provider.AddColumn(tableName, column);
     if (DropThereafter)
     {
         commands = commands.Concat(provider.DropDefault(tableName, new Column(
             column.Name,
             column.DataType,
             column.IsNullable,
             null, false)));
     }
     return commands;
 }