当前位置: 首页>>代码示例>>C#>>正文


C# DdlGeneratorFactory.AlterColumn方法代码示例

本文整理汇总了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");
        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:31,代码来源:MigrationAlterDefault.cs

示例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");
        }
开发者ID:roadrunner75,项目名称:dbschemareader,代码行数:16,代码来源:MigrationAlterColumn.cs

示例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");
        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:17,代码来源:MigrationAlterDefault.cs

示例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");
        }
开发者ID:shiningrise,项目名称:dbschemareader,代码行数:17,代码来源:MigrationAlterColumn.cs

示例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");
        }
开发者ID:Petran15,项目名称:dbschemareader,代码行数:21,代码来源:MigrationAlterDefault.cs

示例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");
        }
开发者ID:roadrunner75,项目名称:dbschemareader,代码行数:16,代码来源:MigrationAlterColumn.cs

示例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");
        }
开发者ID:roadrunner75,项目名称:dbschemareader,代码行数:18,代码来源:MigrationAlterColumn.cs


注:本文中的DatabaseSchemaReader.SqlGen.DdlGeneratorFactory.AlterColumn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。