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


C# IDatabase.CreateSchema方法代码示例

本文整理汇总了C#中IDatabase.CreateSchema方法的典型用法代码示例。如果您正苦于以下问题:C# IDatabase.CreateSchema方法的具体用法?C# IDatabase.CreateSchema怎么用?C# IDatabase.CreateSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDatabase的用法示例。


在下文中一共展示了IDatabase.CreateSchema方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Up

        public void Up(IDatabase db)
        {
            if (!this.IsFeatureSupported(db))
            {
                return;
            }

            const string schemaName = "Schema 29";
            db.CreateSchema(schemaName);

            db.Schemata[schemaName].CreateTable(Tables[0].Name)
                .WithPrimaryKeyColumn("Id", DbType.Int32)
                .WithNotNullableColumn("Column With Default", DbType.DateTime2).HavingCurrentDateTimeAsDefault();

            db.Execute(string.Format(CultureInfo.InvariantCulture, @"INSERT INTO ""{0}"".""{1}"" (""{2}"") VALUES ('{3}')", schemaName, Tables[0].Name, Tables[0].Columns[0], 1));

            // the following ALTER statement has to DROP the old default constraint and create the new one
            db.Schemata[schemaName].Tables[Tables[0].Name].Columns["Column With Default"].AlterToNotNullable(DbType.DateTimeOffset).HavingCurrentDateTimeOffsetAsDefault();

            // renaming the column also needs to rename the default constraint using the schema prefix
            db.Schemata[schemaName].Tables[Tables[0].Name].Columns["Column With Default"].Rename("Column With Default II");

            // check if the default constraint still works
            db.Execute(string.Format(CultureInfo.InvariantCulture, @"INSERT INTO ""{0}"".""{1}"" (""{2}"") VALUES ('{3}')", schemaName, Tables[0].Name, Tables[0].Columns[0], 2));
        }
开发者ID:dradovic,项目名称:MigSharp,代码行数:25,代码来源:Migration29_Altering_DefaultConstraint_in_Custom_Schema.cs

示例2: Up

        public void Up(IDatabase db)
        {
            if (!this.IsFeatureSupported(db))
            {
                return;
            }

            const string schemaName = "Schema27";

            db.CreateSchema(schemaName);

            db.CreateTable("Mig27") // should be created in Schema27
              .WithPrimaryKeyColumn("Id", DbType.Int32).AsIdentity()
              .WithNotNullableColumn("Content", DbType.String);
            db.Execute(@"INSERT INTO ""Schema27"".""Mig27"" ( ""Content"" ) VALUES ( 'Success' )");

            db.Execute(context =>
                {
                    Assert.AreEqual("Schema27", context.StepMetadata.ModuleName);
                    Assert.AreEqual(27L, context.StepMetadata.Migrations.Single().Timestamp);
                    Assert.AreEqual("Test UseModuleNameAsDefaultSchema", context.StepMetadata.Migrations.Single().Tag);
                    Assert.AreEqual(MigrationDirection.Up, context.StepMetadata.Direction);
                    Assert.IsTrue(context.StepMetadata.UseModuleNameAsDefaultSchema, "Passing UseModuleNameAsDefaultSchema to migration metadata failed.");
                });
        }
开发者ID:dradovic,项目名称:MigSharp,代码行数:25,代码来源:Migration27_UseModuleNameAsDefaultSchema.cs

示例3: Up

        public void Up(IDatabase db)
        {
            if (!this.IsFeatureSupported(db))
            {
                return;
            }

            const string schemaName = "Schema26";

            db.CreateSchema(schemaName);

            // make sure the schema was created
            AssertSchema(db, schemaName, true, "Creating Schema26 failed.");

            db.Schemata[schemaName].Drop();

            // make sure the schema does not exist anymore
            AssertSchema(db, schemaName, false, "Dropping Schema26 failed.");
        }
开发者ID:dradovic,项目名称:MigSharp,代码行数:19,代码来源:Migration26_Schema_Creating_and_Dropping.cs

示例4: Up

        public void Up(IDatabase db)
        {
            if (!this.IsFeatureSupported(db))
            {
                return;
            }

            db.CreateSchema("Schema25");

            // create and populate parent table
            db.Schemata["Schema25"].CreateTable("Mig25")
                                   .WithPrimaryKeyColumn("Id", DbType.Int32).AsIdentity()
                                   .WithNotNullableColumn("Content", DbType.String);
            db.Execute(@"INSERT INTO ""Schema25"".""Mig25"" ( ""Content"" ) VALUES ( 'Success' )");

            // create and populate child table
            db.Schemata["Schema25"].CreateTable("Mig25 Child")
                                   .WithPrimaryKeyColumn("Id", DbType.Int32).AsIdentity()
                                   .WithNotNullableColumn("ParentId", DbType.Int32);
            db.Execute(@"INSERT INTO ""Schema25"".""Mig25 Child"" ( ""ParentId"" ) VALUES ( 1 )");

            // test creating a FK within the same schema
            db.Schemata["Schema25"].Tables["Mig25 Child"].AddForeignKeyTo("Mig25")
                                                         .Through("ParentId", "Id");

            // test creating a FK to a table in another schema
            db.CreateTable("Mig25inDbo")
              .WithPrimaryKeyColumn("Id", DbType.Int32).AsIdentity()
              .WithNotNullableColumn("Content", DbType.String);
            db.Execute(@"INSERT INTO ""dbo"".""Mig25inDbo"" ( ""Content"" ) VALUES ( 'Success' )");
            db.Schemata["Schema25"].Tables["Mig25 Child"].AddForeignKeyTo("Mig25inDbo")
                                                          .InSchema("dbo")
                                                          .Through("ParentId", "Id");

            // test renaming within a schema
            db.Schemata["Schema25"].Tables["Mig25"].Rename("Mig25 Renamed");
        }
开发者ID:dradovic,项目名称:MigSharp,代码行数:37,代码来源:Migration25_Schema_Using.cs


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