本文整理汇总了C#中DatabaseSchemaReader.SqlGen.DdlGeneratorFactory.AlterColumn方法的典型用法代码示例。如果您正苦于以下问题:C# DdlGeneratorFactory.AlterColumn方法的具体用法?C# DdlGeneratorFactory.AlterColumn怎么用?C# DdlGeneratorFactory.AlterColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseSchemaReader.SqlGen.DdlGeneratorFactory
的用法示例。
在下文中一共展示了DdlGeneratorFactory.AlterColumn方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSqlServerWithChangingDefault
public void TestSqlServerWithChangingDefault()
{
//arrange
var migration = new DdlGeneratorFactory(SqlType.SqlServer).MigrationGenerator();
var table = MigrationCommon.CreateTestTable("Orders");
table.SchemaOwner = "dbo";
var column = table.FindColumn("NAME");
column.Length = 40;
column.DefaultValue = "'?'";
//create an "original" version of the column (by cloning)
var originalColumn = column.Clone();
originalColumn.DefaultValue = "'UNKNOWN'";
//add a default constraint
var df = new DatabaseConstraint { ConstraintType = ConstraintType.Default, Name = "DF_Orders_Name" };
df.Columns.Add("NAME");
table.AddConstraint(df);
//act
var sql = migration.AlterColumn(table, column, originalColumn);
//assert
//ALTER TABLE [dbo].[Orders] DROP CONSTRAINT [DF_Orders_Name];
//-- Orders from [NAME] VARCHAR (40) NOT NULL to [NAME] VARCHAR (40) NOT NULL
//ALTER TABLE [dbo].[Orders] ALTER COLUMN [NAME] VARCHAR (40) NOT NULL;
//ALTER TABLE [dbo].[Orders] ADD CONSTRAINT [DF_Orders_Name] DEFAULT '?' FOR [NAME];
Assert.IsTrue(sql.Contains("DROP CONSTRAINT [DF_Orders_Name]"), "drop constraint");
Assert.IsTrue(sql.Contains("ADD CONSTRAINT [DF_Orders_Name] DEFAULT '?' FOR [NAME]"), "add default constraint");
}
示例2: TestMySqlWithSchema
public void TestMySqlWithSchema()
{
//arrange
var migration = new DdlGeneratorFactory(SqlType.MySql).MigrationGenerator();
var table = MigrationCommon.CreateTestTable("Orders");
table.SchemaOwner = "dbo";
var column = table.FindColumn("NAME");
column.Length = 40;
//act
var sql = migration.AlterColumn(table, column, null);
//assert
Assert.IsTrue(sql.Contains("ALTER TABLE `dbo`.`Orders` MODIFY `NAME` VARCHAR (40)"), "names should be quoted correctly");
}
示例3: TestSqlServerWithNoDefault
public void TestSqlServerWithNoDefault()
{
//arrange
var migration = new DdlGeneratorFactory(SqlType.SqlServer).MigrationGenerator();
var table = MigrationCommon.CreateTestTable("Orders");
table.SchemaOwner = "dbo";
var column = table.FindColumn("NAME");
column.Length = 40;
//act
var sql = migration.AlterColumn(table, column, null);
//assert
Assert.IsFalse(sql.Contains("ADD CONSTRAINT [DF_Orders_NAME] DEFAULT"), "no add default constraint");
}
示例4: TestOracleNoSchema
public void TestOracleNoSchema()
{
//arrange
var migration = new DdlGeneratorFactory(SqlType.Oracle).MigrationGenerator();
var table = MigrationCommon.CreateTestTable("Orders");
table.SchemaOwner = "dbo";
var column = table.FindColumn("NAME");
column.Length = 40;
//act
migration.IncludeSchema = false;
var sql = migration.AlterColumn(table, column, null);
//assert
Assert.IsTrue(sql.Contains("ALTER TABLE \"Orders\" MODIFY \"NAME\" NVARCHAR2 (40)"), "names should be quoted correctly");
}
示例5: TestSqlServerWithNewDefault
public void TestSqlServerWithNewDefault()
{
//arrange
var migration = new DdlGeneratorFactory(SqlType.SqlServer).MigrationGenerator();
var table = MigrationCommon.CreateTestTable("Orders");
table.SchemaOwner = "dbo";
var column = table.FindColumn("NAME");
column.Length = 40;
column.DefaultValue = "'?'";
//act
var sql = migration.AlterColumn(table, column, null);
//assert
//ALTER TABLE [dbo].[Orders] ALTER COLUMN [NAME] VARCHAR (40) NOT NULL;
//ALTER TABLE [dbo].[Orders] ADD CONSTRAINT [DF_Orders_NAME] DEFAULT '?' FOR [NAME];
Assert.IsTrue(sql.Contains("ALTER COLUMN [NAME] VARCHAR (40) NOT NULL"), "alter column should not have DEFAULT");
Assert.IsTrue(sql.Contains("ADD CONSTRAINT [DF_Orders_NAME] DEFAULT '?' FOR [NAME]"), "add default constraint");
}
示例6: TestSqLite
public void TestSqLite()
{
//arrange
var migration = new DdlGeneratorFactory(SqlType.SQLite).MigrationGenerator();
var table = MigrationCommon.CreateTestTable("Orders");
table.SchemaOwner = "dbo";
var column = table.FindColumn("NAME");
column.Length = 40;
//act
var sql = migration.AlterColumn(table, column, null);
//assert
Assert.IsTrue(sql.StartsWith("--", StringComparison.OrdinalIgnoreCase), "Cannot be changed in SQLite");
}
示例7: TestPostgreSql
public void TestPostgreSql()
{
//arrange
var migration = new DdlGeneratorFactory(SqlType.PostgreSql).MigrationGenerator();
var table = MigrationCommon.CreateTestTable("Orders");
table.SchemaOwner = "dbo";
var column = table.FindColumn("NAME");
column.Length = 40;
//act
var sql = migration.AlterColumn(table, column, null);
//assert
Console.WriteLine(sql);
Assert.IsTrue(sql.Contains("ALTER TABLE \"dbo\".\"Orders\" ALTER COLUMN \"NAME\" TYPE VARCHAR (40)"), "names should be quoted correctly");
Assert.IsTrue(sql.Contains("ALTER TABLE \"dbo\".\"Orders\" ALTER COLUMN \"NAME\" SET NOT NULL;"), "NULL should be handled correctly");
}