public void WriteColumnsChanges(TableSchema table)
        {
            var mods = table.ModifiedColumns.ChangedColumns;
            if (mods.Count == 0) return;
            FillRealTableSchema(table);
            var writer = new SqlServerCompactColumnWriter(Builder);

            foreach (var col in mods.Where(c => c.DefaultDropped))
            {
                Builder.AppendFormat("alter table {0} alter column {1} drop default;\n", table.Name, col.Name);
            }

            foreach (var col in mods.Where(d => !d.IsDropped))
            {
                Builder.AppendFormat("alter table [{0}] alter column {1} ", table.Name,
                                     SqlServerProvider.EscapeIdentifier(col.Current.Name));
                writer.Write(col);
                Builder.AppendLine(";");
            }

            foreach (var cl in mods.Where(c => !string.IsNullOrEmpty(c.DefaultValue)))
            {
                Builder.AppendFormat("alter table {0} alter column {1} set default '{2}';\n", table.Name, cl.Name,
                                     cl.DefaultValue);
            }
        }
示例#2
0
        public void WriteColumnsChanges(TableSchema table)
        {
            var mods = table.ModifiedColumns.ChangedColumns;

            if (mods.Count == 0)
            {
                return;
            }
            FillRealTableSchema(table);
            var writer = new SqlServerCompactColumnWriter(Builder);

            foreach (var col in mods.Where(c => c.DefaultDropped))
            {
                Builder.AppendFormat("alter table {0} alter column {1} drop default;\n", table.Name, col.Name);
            }

            foreach (var col in mods.Where(d => !d.IsDropped))
            {
                Builder.AppendFormat("alter table [{0}] alter column {1} ", table.Name,
                                     SqlServerProvider.EscapeIdentifier(col.Current.Name));
                writer.Write(col);
                Builder.AppendLine(";");
            }

            foreach (var cl in mods.Where(c => !string.IsNullOrEmpty(c.DefaultValue)))
            {
                Builder.AppendFormat("alter table {0} alter column {1} set default '{2}';\n", table.Name, cl.Name,
                                     cl.DefaultValue);
            }
        }