• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Model.CreateTableOperation类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Data.Entity.Migrations.Model.CreateTableOperation的典型用法代码示例。如果您正苦于以下问题:C# CreateTableOperation类的具体用法?C# CreateTableOperation怎么用?C# CreateTableOperation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CreateTableOperation类属于System.Data.Entity.Migrations.Model命名空间,在下文中一共展示了CreateTableOperation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ForeignKey_should_create_and_add_fk_model

        public void ForeignKey_should_create_and_add_fk_model()
        {
            var createTableOperation = new CreateTableOperation("T");
            createTableOperation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Guid)
                    {
                        Name = "Foo"
                    });
            createTableOperation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Guid)
                    {
                        Name = "Bar"
                    });

            var migration = new TestMigration();
            var tableBuilder = new TableBuilder<Columns>(createTableOperation, migration);

            tableBuilder.ForeignKey(
                "P", c => new
                              {
                                  c.Foo,
                                  c.Bar
                              }, true, "my_fk");

            Assert.Equal(1, migration.Operations.Count());

            var addForeignKeyOperation = migration.Operations.Cast<AddForeignKeyOperation>().Single();

            Assert.Equal("P", addForeignKeyOperation.PrincipalTable);
            Assert.Equal("Foo", addForeignKeyOperation.DependentColumns.First());
            Assert.Equal("Bar", addForeignKeyOperation.DependentColumns.Last());
            Assert.True(addForeignKeyOperation.CascadeDelete);
            Assert.Equal("my_fk", addForeignKeyOperation.Name);
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:34,代码来源:TableBuilderTests.cs


示例2: DropTableOperation

        public DropTableOperation(string name, CreateTableOperation inverse, object anonymousArguments = null)
            : this(name, anonymousArguments)
        {
            //Contract.Requires(inverse != null);

            _inverse = inverse;
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:7,代码来源:DropTableOperation.cs


示例3: Generate

        protected override void Generate(CreateTableOperation createTableOperation)
        {
            string schema, objectName;
            this.GetNameParts(createTableOperation.Name, out schema, out objectName);
            using (var writer = Writer())
            {
                writer.WriteLine("IF NOT EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '{0}' AND TABLE_NAME = '{1}')\r\nBEGIN", schema, objectName);
                writer.Indent++;
                writer.Write("CREATE TABLE ");
                writer.Write(this.Name(createTableOperation.Name));
                writer.Write(" ( ");
                int i = 0;
                foreach (var column in createTableOperation.Columns)
                {
                    this.AddColumnDefinition(column, writer);
                    writer.WriteLine("{0}", i != createTableOperation.Columns.Count - 1 ? "," : string.Empty);
                    i++;
                }
                writer.Write(" ) ");
                writer.Indent--;
                writer.Write("\r\nEND");

                this.Statement(writer);
            }
        }
开发者ID:priestofpsi,项目名称:theDiary-Common-Framework,代码行数:25,代码来源:UnifiedContextSqlGenerator.cs


示例4: PrimaryKey_should_set_key_columns_and_name

        public void PrimaryKey_should_set_key_columns_and_name()
        {
            var createTableOperation = new CreateTableOperation("T");
            createTableOperation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Guid)
                    {
                        Name = "Foo"
                    });
            createTableOperation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Guid)
                    {
                        Name = "Bar"
                    });
            createTableOperation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Guid)
                    {
                        Name = "Baz"
                    });

            var tableBuilder = new TableBuilder<Columns>(createTableOperation, new TestMigration());

            tableBuilder.PrimaryKey(
                c => new
                         {
                             c.Bar,
                             c.Foo
                         }, name: "PK_Custom");

            Assert.Equal(2, createTableOperation.PrimaryKey.Columns.Count());
            Assert.Equal("Bar", createTableOperation.PrimaryKey.Columns.First());
            Assert.Equal("Foo", createTableOperation.PrimaryKey.Columns.Last());
            Assert.Equal("PK_Custom", createTableOperation.PrimaryKey.Name);
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:33,代码来源:TableBuilderTests.cs


示例5: DropTableOperation

        public DropTableOperation(string name, CreateTableOperation inverse, object anonymousArguments = null)
            : this(name, anonymousArguments)
        {
            Check.NotNull(inverse, "inverse");

            _inverse = inverse;
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:7,代码来源:DropTableOperation.cs


示例6: Generate

        /// <summary>
        ///     Generates SQL for a <see cref = "CreateTableOperation" />.
        ///     Generated SQL should be added using the Statement method.
        /// </summary>
        /// <param name = "createTableOperation">The operation to produce SQL for.</param>
        protected virtual void Generate(CreateTableOperation createTableOperation)
        {
            Contract.Requires(createTableOperation != null);

            var parts = createTableOperation.Name.Split(new[] { '.' }, 2);

            if (parts.Length > 1)
            {
                var schema = parts[0];

                if (!schema.EqualsIgnoreCase("dbo")
                    && !_generatedSchemas.Contains(schema))
                {
                    GenerateCreateSchema(schema);

                    _generatedSchemas.Add(schema);
                }
            }

            using (var writer = Writer())
            {
                writer.WriteLine("CREATE TABLE " + Name(createTableOperation.Name) + " (");
                writer.Indent++;

                var columnCount = createTableOperation.Columns.Count();

                createTableOperation.Columns.Each(
                    (c, i) =>
                        {
                            Generate(c, writer);

                            if (i < columnCount - 1)
                            {
                                writer.WriteLine(",");
                            }
                        });

                if (createTableOperation.PrimaryKey != null)
                {
                    writer.WriteLine(",");
                    writer.Write("CONSTRAINT ");
                    writer.Write(Quote(createTableOperation.PrimaryKey.Name));
                    writer.Write(" PRIMARY KEY (");
                    writer.Write(createTableOperation.PrimaryKey.Columns.Join(Quote));
                    writer.WriteLine(")");
                }
                else
                {
                    writer.WriteLine();
                }

                writer.Indent--;
                writer.Write(")");

                Statement(writer);
            }

            GenerateMakeSystemTable(createTableOperation);
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:64,代码来源:SqlServerMigrationSqlGenerator.cs


示例7: Generate

 protected override void Generate(CreateTableOperation cto)
 {
     if (cto.PrimaryKey != null)
     {
         cto.PrimaryKey.Name = GetPrimaryKeyName(cto.PrimaryKey.Table);
     }
     base.Generate(cto);
 }
开发者ID:qstream-inactive,项目名称:ENTech-Store,代码行数:8,代码来源:SqlGenerator.cs


示例8: Generate

        protected override void Generate(CreateTableOperation createTableOperation)
        {
            foreach (var columnModel in createTableOperation.Columns) {
                SetDefaultValue(columnModel);
            }

            base.Generate(createTableOperation);
        }
开发者ID:rubenknuijver,项目名称:Jigsaw,代码行数:8,代码来源:CustomSqlServerMigrationSqlGenerator.cs


示例9: Can_set_and_get_primary_key

        public void Can_set_and_get_primary_key()
        {
            var addPrimaryKeyOperation = new AddPrimaryKeyOperation();
            var table = new CreateTableOperation("T") { PrimaryKey = addPrimaryKeyOperation };

            Assert.Same(addPrimaryKeyOperation, table.PrimaryKey);
            Assert.Equal("T", addPrimaryKeyOperation.Table);
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:8,代码来源:CreateTableOperationTests.cs


示例10: Generate

 protected override void Generate(CreateTableOperation createTableOperation, IndentedTextWriter writer)
 {
     var isReadonly = ReadonlyEntities.Contains(createTableOperation.Name);
     if (!isReadonly)
     {
         base.Generate(createTableOperation, writer);
     }
 }
开发者ID:goodwillguy,项目名称:DeviceManagerService,代码行数:8,代码来源:SkipReadonlyEntityCodeMigration.cs


示例11: Inverse_should_produce_drop_table_operation

        public void Inverse_should_produce_drop_table_operation()
        {
            var createTableOperation = new CreateTableOperation("Foo");

            var dropTableOperation = (DropTableOperation)createTableOperation.Inverse;

            Assert.Equal("Foo", dropTableOperation.Name);
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:8,代码来源:CreateTableOperationTests.cs


示例12: Inverse_should_produce_create_table_operation

        public void Inverse_should_produce_create_table_operation()
        {
            var inverse = new CreateTableOperation("T");
            var dropTableOperation = new DropTableOperation("T", inverse);

            Assert.Equal("T", dropTableOperation.Name);
            Assert.Same(inverse, dropTableOperation.Inverse);
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:8,代码来源:DropTableOperationTests.cs


示例13: Annotations_should_return_set_annotations

        public void Annotations_should_return_set_annotations()
        {
            Assert.Empty(new CreateTableOperation("Foo").Annotations);
            Assert.Empty(new CreateTableOperation("Foo", null).Annotations);

            var operation = new CreateTableOperation("Foo", new Dictionary<string, object> { { "A1", "V1" } });

            Assert.Equal("V1", operation.Annotations["A1"]);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:9,代码来源:CreateTableOperationTests.cs


示例14: Generate

        protected override void Generate(CreateTableOperation createTableOperation)
        {
            if ((createTableOperation.PrimaryKey != null)
                && !createTableOperation.PrimaryKey.IsClustered)
            {
                createTableOperation.PrimaryKey.IsClustered = true;
            }

            base.Generate(createTableOperation);
        }
开发者ID:dragana-berber,项目名称:FarmAppReborn,代码行数:10,代码来源:AzureSqlGenerator.cs


示例15: Can_get_and_set_create_table_operation

        public void Can_get_and_set_create_table_operation()
        {
            var createTableOperation = new CreateTableOperation("T");

            var dropPrimaryKeyOperation = new DropPrimaryKeyOperation
            {
                CreateTableOperation = createTableOperation
            };

            Assert.Same(createTableOperation, dropPrimaryKeyOperation.CreateTableOperation);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:11,代码来源:DropPrimaryKeyOperationTests.cs


示例16: Can_add_and_enumerate_columns

        public void Can_add_and_enumerate_columns()
        {
            var createTableOperation = new CreateTableOperation("Foo");
            createTableOperation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Int64)
                    {
                        Name = "Bar",
                        IsNullable = true
                    });

            Assert.NotNull(createTableOperation.Columns.Single());
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:12,代码来源:CreateTableOperationTests.cs


示例17: Inverse_should_return_set_create_table_operation

        public void Inverse_should_return_set_create_table_operation()
        {
            var inverse = new CreateTableOperation("T");
            var operation = new DropTableOperation("T", inverse);

            Assert.Equal("T", operation.Name);
            Assert.Same(inverse, operation.Inverse);

            operation = new DropTableOperation("T", null, null, inverse);

            Assert.Equal("T", operation.Name);
            Assert.Same(inverse, operation.Inverse);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:13,代码来源:DropTableOperationTests.cs


示例18: Generate

        protected override void Generate(CreateTableOperation createTableOperation)
        {
            if (createTableOperation == null)
            {
                throw new ArgumentNullException("createTableOperation");
            }

            // turn off clustered index for all PKs (except for migration history)
            if (!createTableOperation.Name.Contains("__MigrationHistory"))
            {
                createTableOperation.PrimaryKey.IsClustered = false;
            }

            base.Generate(createTableOperation);
        }
开发者ID:dmayhak,项目名称:HyperSlackers.DbContext,代码行数:15,代码来源:HyperSqlServerMigrationSqlGenerator.cs


示例19: Inverse_should_produce_drop_table_operation

        public void Inverse_should_produce_drop_table_operation()
        {
            var operation = new CreateTableOperation(
                "Foo", new Dictionary<string, object>
                {
                    { "AT1", "VT1" },
                    { "AT2", "VT2" }
                });

            operation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Int64)
                {
                    Name = "C1",
                    Annotations = new Dictionary<string, AnnotationValues>
                    {
                        { "AC1A", new AnnotationValues(null, "VC1A") },
                        { "AC1B", new AnnotationValues(null, "VC1B") }
                    }
                });

            operation.Columns.Add(
                new ColumnModel(PrimitiveTypeKind.Int64)
                {
                    Name = "C2",
                    Annotations = new Dictionary<string, AnnotationValues>
                    {
                        { "AC2A", new AnnotationValues(null, "VC2A") },
                        { "AC2B", new AnnotationValues(null, "VC2B") }
                    }
                });

            var inverse = (DropTableOperation)operation.Inverse;

            Assert.Equal("Foo", inverse.Name);

            Assert.Equal("VT1", inverse.RemovedAnnotations["AT1"]);
            Assert.Equal("VT2", inverse.RemovedAnnotations["AT2"]);

            Assert.Equal("VC1A", inverse.RemovedColumnAnnotations["C1"]["AC1A"]);
            Assert.Equal("VC1B", inverse.RemovedColumnAnnotations["C1"]["AC1B"]);
            Assert.Equal("VC2A", inverse.RemovedColumnAnnotations["C2"]["AC2A"]);
            Assert.Equal("VC2B", inverse.RemovedColumnAnnotations["C2"]["AC2B"]);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:43,代码来源:CreateTableOperationTests.cs


示例20: Index_should_add_create_index_operation_to_model

        public void Index_should_add_create_index_operation_to_model()
        {
            var createTableOperation = new CreateTableOperation("T");
            createTableOperation.Columns.Add(new ColumnModel(PrimitiveTypeKind.Guid) { Name = "Foo" });
            createTableOperation.Columns.Add(new ColumnModel(PrimitiveTypeKind.Guid) { Name = "Bar" });

            var migration = new TestMigration();
            var tableBuilder = new TableBuilder<Columns>(createTableOperation, migration);

            tableBuilder.Index(c => new { c.Foo, c.Bar }, unique: true);

            Assert.Equal(1, migration.Operations.Count());

            var createIndexOperation
                = migration.Operations.Cast<CreateIndexOperation>().Single();

            Assert.Equal("T", createIndexOperation.Table);
            Assert.True(createIndexOperation.IsUnique);
            Assert.Equal("Foo", createIndexOperation.Columns.First());
            Assert.Equal("Bar", createIndexOperation.Columns.Last());
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:21,代码来源:TableBuilderTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Utilities.IndentedTextWriter类代码示例发布时间:2022-05-26
下一篇:
C# Model.ColumnModel类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap