當前位置: 首頁>>代碼示例>>C#>>正文


C# Npgsql.NpgsqlMigrationSqlGenerator類代碼示例

本文整理匯總了C#中Npgsql.NpgsqlMigrationSqlGenerator的典型用法代碼示例。如果您正苦於以下問題:C# NpgsqlMigrationSqlGenerator類的具體用法?C# NpgsqlMigrationSqlGenerator怎麽用?C# NpgsqlMigrationSqlGenerator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


NpgsqlMigrationSqlGenerator類屬於Npgsql命名空間,在下文中一共展示了NpgsqlMigrationSqlGenerator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TestUpdateDatabaseOperation

 public void TestUpdateDatabaseOperation()
 {
     var operations = new List<MigrationOperation>();
     //TODO: fill operations
     var statments = new NpgsqlMigrationSqlGenerator().Generate(operations, BackendVersion.ToString());
     //TODO: check statments
 }
開發者ID:hultqvist,項目名稱:Npgsql2,代碼行數:7,代碼來源:EntityFrameworkMigrationTests.cs

示例2: TestAddForeignKeyOperationCascadeDelete

 public void TestAddForeignKeyOperationCascadeDelete()
 {
     var operations = new List<MigrationOperation>();
     var operation = new AddForeignKeyOperation();
     operation.Name = "someFK";
     operation.PrincipalTable = "somePrincipalTable";
     operation.DependentTable = "someDependentTable";
     operation.DependentColumns.Add("column1");
     operation.DependentColumns.Add("column2");
     operation.DependentColumns.Add("column3");
     operation.CascadeDelete = true;
     operations.Add(operation);
     var statments = new NpgsqlMigrationSqlGenerator().Generate(operations, BackendVersion.ToString());
     Assert.AreEqual(1, statments.Count());
     Assert.AreEqual("ALTER TABLE \"someDependentTable\" ADD CONSTRAINT \"someFK\" FOREIGN KEY (\"column1\",\"column2\",\"column3\") REFERENCES \"somePrincipalTable\" ) ON DELETE CASCADE", statments.ElementAt(0).Sql);
 }
開發者ID:hultqvist,項目名稱:Npgsql2,代碼行數:16,代碼來源:EntityFrameworkMigrationTests.cs

示例3: TestRenameColumnOperation

 public void TestRenameColumnOperation()
 {
     var operations = new List<MigrationOperation>();
     operations.Add(new RenameColumnOperation("someTable", "someOldColumnName", "someNewColumnName"));
     var statments = new NpgsqlMigrationSqlGenerator().Generate(operations, BackendVersion.ToString());
     Assert.AreEqual(1, statments.Count());
     Assert.AreEqual("ALTER TABLE \"someTable\" RENAME COLUMN \"someOldColumnName\" TO \"someNewColumnName\"", statments.ElementAt(0).Sql);
 }
開發者ID:hultqvist,項目名稱:Npgsql2,代碼行數:8,代碼來源:EntityFrameworkMigrationTests.cs

示例4: TestSqlOperation

 public void TestSqlOperation()
 {
     var operations = new List<MigrationOperation>();
     operations.Add(new SqlOperation("SELECT someColumn FROM someTable"));
     var statments = new NpgsqlMigrationSqlGenerator().Generate(operations, BackendVersion.ToString());
     Assert.AreEqual(1, statments.Count());
     Assert.AreEqual("SELECT someColumn FROM someTable", statments.ElementAt(0).Sql);
 }
開發者ID:hultqvist,項目名稱:Npgsql2,代碼行數:8,代碼來源:EntityFrameworkMigrationTests.cs

示例5: TestAddPrimaryKeyOperationClustered

 public void TestAddPrimaryKeyOperationClustered()
 {
     var operations = new List<MigrationOperation>();
     var operation = new AddPrimaryKeyOperation();
     operation.Table = "someTable";
     operation.Name = "somePKName";
     operation.Columns.Add("column1");
     operation.Columns.Add("column2");
     operation.Columns.Add("column3");
     operation.IsClustered = true;
     //TODO: PostgreSQL support something like IsClustered?
     operations.Add(operation);
     var statments = new NpgsqlMigrationSqlGenerator().Generate(operations, BackendVersion.ToString());
     Assert.AreEqual(1, statments.Count());
     Assert.AreEqual("ALTER TABLE \"someTable\" ADD CONSTRAINT \"somePKName\" PRIMARY KEY (\"column1\",\"column2\",\"column3\")", statments.ElementAt(0).Sql);
 }
開發者ID:hultqvist,項目名稱:Npgsql2,代碼行數:16,代碼來源:EntityFrameworkMigrationTests.cs

示例6: TestDropPrimaryKeyOperation

 public void TestDropPrimaryKeyOperation()
 {
     var operations = new List<MigrationOperation>();
     var operation = new DropPrimaryKeyOperation();
     operation.Table = "someTable";
     operation.Name = "somePKName";
     operations.Add(operation);
     var statments = new NpgsqlMigrationSqlGenerator().Generate(operations, BackendVersion.ToString());
     Assert.AreEqual(1, statments.Count());
     Assert.AreEqual("ALTER TABLE \"someTable\" DROP CONSTRAINT \"somePKName\"", statments.ElementAt(0).Sql);
 }
開發者ID:hultqvist,項目名稱:Npgsql2,代碼行數:11,代碼來源:EntityFrameworkMigrationTests.cs

示例7: TestCreateIndexOperationUnique

 public void TestCreateIndexOperationUnique()
 {
     var operations = new List<MigrationOperation>();
     var operation = new CreateIndexOperation();
     operation.Table = "someTable";
     operation.Name = "someIndex";
     operation.Columns.Add("column1");
     operation.Columns.Add("column2");
     operation.Columns.Add("column3");
     operation.IsUnique = true;
     operations.Add(operation);
     var statments = new NpgsqlMigrationSqlGenerator().Generate(operations, BackendVersion.ToString());
     Assert.AreEqual(1, statments.Count());
     Assert.AreEqual("CREATE UNIQUE INDEX \"someTable_someIndex\" ON \"someTable\" (\"column1\",\"column2\",\"column3\")", statments.ElementAt(0).Sql);
 }
開發者ID:hultqvist,項目名稱:Npgsql2,代碼行數:15,代碼來源:EntityFrameworkMigrationTests.cs

示例8: RenameTableOperation

 public void RenameTableOperation()
 {
     var operations = new List<MigrationOperation>();
     operations.Add(new RenameTableOperation("schema.someOldTableName", "someNewTablename"));
     var statments = new NpgsqlMigrationSqlGenerator().Generate(operations, BackendVersion.ToString());
     Assert.AreEqual(1, statments.Count());
     Assert.AreEqual("ALTER TABLE \"schema\".\"someOldTableName\" RENAME TO \"someNewTablename\"", statments.ElementAt(0).Sql);
 }
開發者ID:kraaden,項目名稱:npgsql,代碼行數:8,代碼來源:EntityFrameworkMigrationTests.cs

示例9: TestDropTableOperation

 public void TestDropTableOperation()
 {
     var operations = new List<MigrationOperation>();
     operations.Add(new DropTableOperation("someTable"));
     var statments = new NpgsqlMigrationSqlGenerator().Generate(operations, BackendVersion.ToString());
     Assert.AreEqual(1, statments.Count());
     Assert.AreEqual("DROP TABLE \"someTable\"", statments.ElementAt(0).Sql);
 }
開發者ID:hultqvist,項目名稱:Npgsql2,代碼行數:8,代碼來源:EntityFrameworkMigrationTests.cs

示例10: TestDropIndexOperationTableNameWithSchema

 public void TestDropIndexOperationTableNameWithSchema()
 {
     var operations = new List<MigrationOperation>();
     operations.Add(new DropIndexOperation()
     {
         Name = "someIndex",
         Table = "someSchema.someTable"
     });
     var statments = new NpgsqlMigrationSqlGenerator().Generate(operations, BackendVersion.ToString());
     Assert.AreEqual(1, statments.Count());
     Assert.AreEqual("DROP INDEX IF EXISTS someSchema.\"someTable_someIndex\"", statments.ElementAt(0).Sql);
 }
開發者ID:hultqvist,項目名稱:Npgsql2,代碼行數:12,代碼來源:EntityFrameworkMigrationTests.cs

示例11: TestCreateTableOperation

        public void TestCreateTableOperation()
        {
            var operations = new List<MigrationOperation>();
            var operation = new CreateTableOperation("someSchema.someTable");

            operation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.String)
                {
                    Name = "SomeString",
                    MaxLength = 233,
                    IsNullable = false
                });

            operation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.String)
                {
                    Name = "AnotherString",
                    IsNullable = true
                });

            operation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Binary)
                {
                    Name = "SomeBytes"
                });

            operation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Int64)
                {
                    Name = "SomeLong",
                    IsIdentity = true
                });

            operation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.DateTime)
                {
                    Name = "SomeDateTime"
                });

            operations.Add(operation);
            var statments = new NpgsqlMigrationSqlGenerator().Generate(operations, BackendVersion.ToString());
            Assert.AreEqual(2, statments.Count());
            if (BackendVersion.Major > 9 || (BackendVersion.Major == 9 && BackendVersion.Minor > 2))
                Assert.AreEqual("CREATE SCHEMA IF NOT EXISTS someSchema", statments.ElementAt(0).Sql);
            else
                Assert.AreEqual("CREATE SCHEMA someSchema", statments.ElementAt(0).Sql);
            Assert.AreEqual("CREATE TABLE \"someSchema\".\"someTable\"(\"SomeString\" text NOT NULL DEFAULT '',\"AnotherString\" text,\"SomeBytes\" bytea,\"SomeLong\" serial8,\"SomeDateTime\" timestamp)", statments.ElementAt(1).Sql);
        }
開發者ID:hultqvist,項目名稱:Npgsql2,代碼行數:48,代碼來源:EntityFrameworkMigrationTests.cs

示例12: TestAlterColumnOperationDefaultAndNullable

 public void TestAlterColumnOperationDefaultAndNullable()
 {
     var operations = new List<MigrationOperation>();
     operations.Add(new AlterColumnOperation("tableName", new ColumnModel(PrimitiveTypeKind.Double)
     {
         Name = "columnName",
         DefaultValue = 2.3,
         IsNullable = false
     }, false));
     var statments = new NpgsqlMigrationSqlGenerator().Generate(operations, BackendVersion.ToString());
     Assert.AreEqual(3, statments.Count());
     Assert.AreEqual("ALTER TABLE \"tableName\" ALTER COLUMN \"columnName\" TYPE float8", statments.ElementAt(0).Sql);
     Assert.AreEqual("ALTER TABLE \"tableName\" ALTER COLUMN \"columnName\" SET NOT NULL", statments.ElementAt(1).Sql);
     Assert.AreEqual("ALTER TABLE \"tableName\" ALTER COLUMN \"columnName\" SET DEFAULT 2.3", statments.ElementAt(2).Sql);
 }
開發者ID:hultqvist,項目名稱:Npgsql2,代碼行數:15,代碼來源:EntityFrameworkMigrationTests.cs

示例13: TestAddColumnOperationDefaultValueSql

 public void TestAddColumnOperationDefaultValueSql()
 {
     var operations = new List<MigrationOperation>();
     operations.Add(new AddColumnOperation("tableName", new ColumnModel(PrimitiveTypeKind.Single)
     {
         Name = "columnName",
         DefaultValueSql = "4.6"
     }));
     var statments = new NpgsqlMigrationSqlGenerator().Generate(operations, BackendVersion.ToString());
     Assert.AreEqual(1, statments.Count());
     Assert.AreEqual("ALTER TABLE \"tableName\" ADD \"columnName\" float4 DEFAULT 4.6", statments.ElementAt(0).Sql);
 }
開發者ID:hultqvist,項目名稱:Npgsql2,代碼行數:12,代碼來源:EntityFrameworkMigrationTests.cs

示例14: TestDropForeignKeyOperation

 public void TestDropForeignKeyOperation()
 {
     var operations = new List<MigrationOperation>();
     var operation = new DropForeignKeyOperation();
     operation.Name = "someFK";
     operation.DependentTable = "someTable";
     operations.Add(operation);
     var statments = new NpgsqlMigrationSqlGenerator().Generate(operations, BackendVersion.ToString());
     Assert.AreEqual(1, statments.Count());
     if (BackendVersion.Major > 8)
         Assert.AreEqual("ALTER TABLE \"someTable\" DROP CONSTRAINT IF EXISTS \"someFK\"", statments.ElementAt(0).Sql);
     else
         Assert.AreEqual("ALTER TABLE \"someTable\" DROP CONSTRAINT \"someFK\"", statments.ElementAt(0).Sql);
 }
開發者ID:hultqvist,項目名稱:Npgsql2,代碼行數:14,代碼來源:EntityFrameworkMigrationTests.cs

示例15: TestMoveTableOperationNewSchemaIsNull

 public void TestMoveTableOperationNewSchemaIsNull()
 {
     var operations = new List<MigrationOperation>();
     operations.Add(new MoveTableOperation("someOldSchema.someTable", null));
     var statments = new NpgsqlMigrationSqlGenerator().Generate(operations, BackendVersion.ToString());
     Assert.AreEqual(2, statments.Count());
     if (BackendVersion.Major > 9 || (BackendVersion.Major == 9 && BackendVersion.Minor > 2))
         Assert.AreEqual("CREATE SCHEMA IF NOT EXISTS dbo", statments.ElementAt(0).Sql);
     else
         Assert.AreEqual("CREATE SCHEMA dbo", statments.ElementAt(0).Sql);
     Assert.AreEqual("ALTER TABLE \"someOldSchema\".\"someTable\" SET SCHEMA dbo", statments.ElementAt(1).Sql);
 }
開發者ID:hultqvist,項目名稱:Npgsql2,代碼行數:12,代碼來源:EntityFrameworkMigrationTests.cs


注:本文中的Npgsql.NpgsqlMigrationSqlGenerator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。