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

C# Model.AddPrimaryKeyOperation类代码示例

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

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



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

示例1: Can_get_default_for_name

        public void Can_get_default_for_name()
        {
            var addPrimaryKeyOperation = new AddPrimaryKeyOperation { Table = "T" };

            Assert.Equal("PK_T", addPrimaryKeyOperation.Name);
            Assert.True(addPrimaryKeyOperation.HasDefaultName);
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:7,代码来源:AddPrimaryKeyOperationTests.cs


示例2: 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


示例3: DefaultName_is_restricted_to_128_chars

        public void DefaultName_is_restricted_to_128_chars()
        {
            var addPrimaryKeyOperation = new AddPrimaryKeyOperation
                                             {
                                                 Table = new string('t', 150)
                                             };

            Assert.Equal(128, addPrimaryKeyOperation.DefaultName.Length);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:9,代码来源:AddPrimaryKeyOperationTests.cs


示例4: Can_get_and_set_table_and_name_and_columns

        public void Can_get_and_set_table_and_name_and_columns()
        {
            var addPrimaryKeyOperation = new AddPrimaryKeyOperation { Table = "T", Name = "Pk" };

            addPrimaryKeyOperation.Columns.Add("pk2");

            Assert.Equal("T", addPrimaryKeyOperation.Table);
            Assert.Equal("Pk", addPrimaryKeyOperation.Name);
            Assert.Equal("pk2", addPrimaryKeyOperation.Columns.Single());
            Assert.False(addPrimaryKeyOperation.HasDefaultName);
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:11,代码来源:AddPrimaryKeyOperationTests.cs


示例5: Inverse_should_return_drop_operation

        public void Inverse_should_return_drop_operation()
        {
            var addPrimaryKeyOperation = new AddPrimaryKeyOperation { Table = "T", Name = "Pk" };

            addPrimaryKeyOperation.Columns.Add("pk2");

            var inverse = (DropPrimaryKeyOperation)addPrimaryKeyOperation.Inverse;

            Assert.Equal("T", inverse.Table);
            Assert.Equal("Pk", inverse.Name);
            Assert.Equal("pk2", inverse.Columns.Single());
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:12,代码来源:AddPrimaryKeyOperationTests.cs


示例6: Generate

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

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


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


示例7: Convert

        private void Convert(AddPrimaryKeyOperation addPrimaryKeyOperation)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("ALTER TABLE ");
            AppendTableName(addPrimaryKeyOperation.Table, sql);
            sql.Append(" ADD CONSTRAINT \"");
            sql.Append(addPrimaryKeyOperation.Name);
            sql.Append("\" PRIMARY KEY ");

            sql.Append("(");
            foreach (var column in addPrimaryKeyOperation.Columns)
            {
                sql.Append('"');
                sql.Append(column);
                sql.Append("\",");
            }
            sql.Remove(sql.Length - 1, 1);
            sql.Append(")");
            AddStatment(sql);
        }
开发者ID:mono,项目名称:linux-packaging-npgsql,代码行数:20,代码来源:NpgsqlMigrationSqlGenerator.cs


示例8: GetUpgradeOperations

        public virtual IEnumerable<MigrationOperation> GetUpgradeOperations()
        {
            if (!Exists())
            {
                yield break;
            }

            DbConnection connection = null;
            try
            {
                connection = CreateConnection();

                var tableName = "dbo." + HistoryContext.DefaultTableName;

                DbProviderManifest providerManifest;
                if (connection.GetProviderInfo(out providerManifest).IsSqlCe())
                {
                    tableName = HistoryContext.DefaultTableName;
                }

                using (var context = new LegacyHistoryContext(connection))
                {
                    var createdOnExists = false;

                    try
                    {
                        InjectInterceptionContext(context);

                        using (new TransactionScope(TransactionScopeOption.Suppress))
                        {
                            context.History
                                .Select(h => h.CreatedOn)
                                .FirstOrDefault();
                        }

                        createdOnExists = true;
                    }
                    catch (EntityException)
                    {
                    }

                    if (createdOnExists)
                    {
                        yield return new DropColumnOperation(tableName, "CreatedOn");
                    }
                }

                using (var context = CreateContext(connection))
                {
                    if (!_contextKeyColumnExists)
                    {
                        if (_historyContextFactory != HistoryContext.DefaultFactory)
                        {
                            throw Error.UnableToUpgradeHistoryWhenCustomFactory();
                        }

                        yield return new AddColumnOperation(
                            tableName,
                            new ColumnModel(PrimitiveTypeKind.String)
                                {
                                    MaxLength = _contextKeyMaxLength,
                                    Name = "ContextKey",
                                    IsNullable = false,
                                    DefaultValue = _contextKey
                                });

                        var emptyModel = new DbModelBuilder().Build(connection).GetModel();
                        var createTableOperation = (CreateTableOperation)
                            new EdmModelDiffer().Diff(emptyModel, context.GetModel()).Single();

                        var dropPrimaryKeyOperation
                            = new DropPrimaryKeyOperation
                                {
                                    Table = tableName,
                                    CreateTableOperation = createTableOperation
                                };

                        dropPrimaryKeyOperation.Columns.Add("MigrationId");

                        yield return dropPrimaryKeyOperation;

                        yield return new AlterColumnOperation(
                            tableName,
                            new ColumnModel(PrimitiveTypeKind.String)
                                {
                                    MaxLength = _migrationIdMaxLength,
                                    Name = "MigrationId",
                                    IsNullable = false
                                },
                            isDestructiveChange: false);

                        var addPrimaryKeyOperation
                            = new AddPrimaryKeyOperation
                                {
                                    Table = tableName
                                };

                        addPrimaryKeyOperation.Columns.Add("MigrationId");
                        addPrimaryKeyOperation.Columns.Add("ContextKey");

//.........这里部分代码省略.........
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:101,代码来源:HistoryRepository.cs


示例9: Create_operations_to_upgrade_primary_key_of_history_table

        private static MigrationOperation[] Create_operations_to_upgrade_primary_key_of_history_table()
        {
            const string tableName = "dbo." + HistoryContext.DefaultTableName;

            CreateTableOperation createTableOperation;
            using (var context = new HistoryContext())
            {
                var emptyModel = new DbModelBuilder()
                    .Build(context.Database.Connection).GetModel();
                createTableOperation = (CreateTableOperation)
                                       new EdmModelDiffer().Diff(emptyModel, context.GetModel()).Single();
            }

            var addColumnOperation =
                new AddColumnOperation(
                    tableName,
                    new ColumnModel(PrimitiveTypeKind.String)
                        {
                            MaxLength = 512,
                            Name = "ContextKey",
                            IsNullable = false,
                            DefaultValue = "DefaultContextKey"
                        });

            var dropPrimaryKeyOperation
                = new DropPrimaryKeyOperation
                      {
                          Table = tableName,
                          CreateTableOperation = createTableOperation
                      };

            dropPrimaryKeyOperation.Columns.Add("MigrationId");

            var alterColumnOperation
                = new AlterColumnOperation(
                    tableName,
                    new ColumnModel(PrimitiveTypeKind.String)
                        {
                            MaxLength = 150,
                            Name = "MigrationId",
                            IsNullable = false
                        },
                    isDestructiveChange: false);

            var addPrimaryKeyOperation
                = new AddPrimaryKeyOperation
                      {
                          Table = tableName
                      };

            addPrimaryKeyOperation.Columns.Add("MigrationId");
            addPrimaryKeyOperation.Columns.Add("ContextKey");

            return
                new MigrationOperation[]
                    {
                        addColumnOperation,
                        dropPrimaryKeyOperation,
                        alterColumnOperation,
                        addPrimaryKeyOperation
                    };
        }
开发者ID:jesusico83,项目名称:Telerik,代码行数:62,代码来源:SqlServerMigrationSqlGeneratorTests.cs


示例10: Generate_can_output_add_primary_key_operation

        public void Generate_can_output_add_primary_key_operation()
        {
            var migrationProvider = new SqlServerMigrationSqlGenerator();

            var addPrimaryKeyOperation = new AddPrimaryKeyOperation { Table = "T" };

            addPrimaryKeyOperation.Columns.Add("c1");
            addPrimaryKeyOperation.Columns.Add("c2");

            var sql = migrationProvider.Generate(new[] { addPrimaryKeyOperation }, "2008").Join(s => s.Sql, Environment.NewLine);

            Assert.True(sql.Contains("ALTER TABLE [T] ADD CONSTRAINT [PK_T] PRIMARY KEY ([c1], [c2])"));
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:13,代码来源:SqlServerMigrationSqlGeneratorTests.cs


示例11: BuildChangePrimaryKeyOperations

        private static IEnumerable<PrimaryKeyOperation> BuildChangePrimaryKeyOperations(
            string oldTable, string newTable, XElement oldKey, XElement newKey)
        {
            var dropPrimaryKeyOperation = new DropPrimaryKeyOperation
                                              {
                                                  Table = oldTable
                                              };

            oldKey.Descendants(EdmXNames.Ssdl.PropertyRefNames).Each(
                pr => dropPrimaryKeyOperation.Columns.Add(pr.NameAttribute()));

            yield return dropPrimaryKeyOperation;

            var addPrimaryKeyOperation = new AddPrimaryKeyOperation
                                             {
                                                 Table = newTable
                                             };

            newKey.Descendants(EdmXNames.Ssdl.PropertyRefNames).Each(
                pr => addPrimaryKeyOperation.Columns.Add(pr.NameAttribute()));

            yield return addPrimaryKeyOperation;
        }
开发者ID:junxy,项目名称:entityframework,代码行数:23,代码来源:EdmModelDiffer.cs


示例12: BuildCreateTableOperation

        private CreateTableOperation BuildCreateTableOperation(
            string entitySetName,
            string tableName,
            string schema,
            string isSystem,
            ModelMetadata modelMetadata)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(entitySetName));
            Contract.Requires(!string.IsNullOrWhiteSpace(tableName));
            Contract.Requires(!string.IsNullOrWhiteSpace(schema));
            Contract.Requires(modelMetadata != null);

            var createTableOperation = new CreateTableOperation(GetQualifiedTableName(tableName, schema));

            var entityTypeElement = modelMetadata.Model.Descendants(EdmXNames.Ssdl.EntityTypeNames)
                .Single(et => et.NameAttribute().EqualsIgnoreCase(entitySetName));

            entityTypeElement
                .Descendants(EdmXNames.Ssdl.PropertyNames)
                .Each(p => createTableOperation.Columns.Add(BuildColumnModel(p, entitySetName, modelMetadata)));

            var addPrimaryKeyOperation = new AddPrimaryKeyOperation();

            entityTypeElement
                .Descendants(EdmXNames.Ssdl.PropertyRefNames)
                .Each(pr => addPrimaryKeyOperation.Columns.Add(pr.NameAttribute()));

            createTableOperation.PrimaryKey = addPrimaryKeyOperation;
            createTableOperation.IsSystem = isSystem.EqualsIgnoreCase("true");

            return createTableOperation;
        }
开发者ID:junxy,项目名称:entityframework,代码行数:32,代码来源:EdmModelDiffer.cs


示例13: Generate

        /// <summary>
        ///     Generates code to perform an <see cref = "AddPrimaryKeyOperation" />.
        /// </summary>
        /// <param name = "addPrimaryKeyOperation">The operation to generate code for.</param>
        /// <param name = "writer">Text writer to add the generated code to.</param>
        protected virtual void Generate(AddPrimaryKeyOperation addPrimaryKeyOperation, IndentedTextWriter writer)
        {
            Contract.Requires(addPrimaryKeyOperation != null);
            Contract.Requires(writer != null);

            writer.Write("AddPrimaryKey(");
            writer.Write(Quote(addPrimaryKeyOperation.Table));
            writer.Write(", ");

            var compositeIndex = addPrimaryKeyOperation.Columns.Count() > 1;

            if (compositeIndex)
            {
                writer.Write("New String() { ");
            }

            writer.Write(addPrimaryKeyOperation.Columns.Join(Quote));

            if (compositeIndex)
            {
                writer.Write(" }");
            }

            if (!addPrimaryKeyOperation.HasDefaultName)
            {
                writer.Write(", name := ");
                writer.Write(Quote(addPrimaryKeyOperation.Name));
            }

            writer.WriteLine(")");
        }
开发者ID:WangWilliam,项目名称:EntityFramework5,代码行数:36,代码来源:VisualBasicMigrationCodeGenerator.cs


示例14: Generate

 protected override void Generate(AddPrimaryKeyOperation addPrimaryKeyOperation, IndentedTextWriter writer)
 {
     addPrimaryKeyOperation.Table = TrimSchemaPrefix(addPrimaryKeyOperation.Table);
       base.Generate(addPrimaryKeyOperation, writer);
 }
开发者ID:schivei,项目名称:mysql-connector-net,代码行数:5,代码来源:MySqlMigrationSqlGenerator.cs


示例15: Generate

        /// <summary>
        /// Generates SQL for a <see cref="AddPrimaryKeyOperation" />.
        /// Generated SQL should be added using the Statement method.
        /// </summary>
        /// <param name="addPrimaryKeyOperation"> The operation to produce SQL for. </param>
        protected virtual void Generate(AddPrimaryKeyOperation addPrimaryKeyOperation)
        {
            Check.NotNull(addPrimaryKeyOperation, "addPrimaryKeyOperation");

            using (var writer = Writer())
            {
                writer.Write("ALTER TABLE ");
                writer.Write(Name(addPrimaryKeyOperation.Table));
                writer.Write(" ADD CONSTRAINT ");
                writer.Write(Quote(addPrimaryKeyOperation.Name));
                writer.Write(" PRIMARY KEY ");

                if (!addPrimaryKeyOperation.IsClustered)
                {
                    writer.Write("NONCLUSTERED ");
                }

                writer.Write("(");
                writer.Write(addPrimaryKeyOperation.Columns.Select(Quote).Join());
                writer.Write(")");

                Statement(writer);
            }
        }
开发者ID:aspnet,项目名称:EntityFramework6,代码行数:29,代码来源:SqlServerMigrationSqlGenerator.cs


示例16: Generate

        /// <summary>
        /// Generates code to perform an <see cref="AddPrimaryKeyOperation" />.
        /// </summary>
        /// <param name="addPrimaryKeyOperation"> The operation to generate code for. </param>
        /// <param name="writer"> Text writer to add the generated code to. </param>
        protected virtual void Generate(AddPrimaryKeyOperation addPrimaryKeyOperation, IndentedTextWriter writer)
        {
            Check.NotNull(addPrimaryKeyOperation, "addPrimaryKeyOperation");
            Check.NotNull(writer, "writer");

            writer.Write("AddPrimaryKey(");
            writer.Write(Quote(addPrimaryKeyOperation.Table));
            writer.Write(", ");

            var compositeIndex = addPrimaryKeyOperation.Columns.Count() > 1;

            if (compositeIndex)
            {
                writer.Write("New String() { ");
            }

            writer.Write(addPrimaryKeyOperation.Columns.Join(Quote));

            if (compositeIndex)
            {
                writer.Write(" }");
            }

            if (!addPrimaryKeyOperation.HasDefaultName)
            {
                writer.Write(", name := ");
                writer.Write(Quote(addPrimaryKeyOperation.Name));
            }

            if (!addPrimaryKeyOperation.IsClustered)
            {
                writer.Write(", clustered := False");
            }

            writer.WriteLine(")");
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:41,代码来源:VisualBasicMigrationCodeGenerator.cs


示例17: Generate_can_output_add_primary_key_with_non_clustered_index

        public void Generate_can_output_add_primary_key_with_non_clustered_index()
        {
            var codeGenerator = new CSharpMigrationCodeGenerator();

            var addPrimaryKeyOperation
                = new AddPrimaryKeyOperation
                {
                    Table = "T",
                    Name = "PK",
                    IsClustered = false
                };

            addPrimaryKeyOperation.Columns.Add("c1");
            addPrimaryKeyOperation.Columns.Add("c2");

            var generatedMigration
                = codeGenerator.Generate(
                    "Migration",
                    new MigrationOperation[] { addPrimaryKeyOperation },
                    "Source",
                    "Target",
                    "Foo",
                    "Bar");

            Assert.Equal(
                @"namespace Foo
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Bar : DbMigration
    {
        public override void Up()
        {
            AddPrimaryKey(""T"", new[] { ""c1"", ""c2"" }, name: ""PK"", clustered: false);
        }
        
        public override void Down()
        {
            DropPrimaryKey(""T"", name: ""PK"");
        }
    }
}
",
                generatedMigration.UserCode);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:46,代码来源:CSharpMigrationCodeGeneratorTests.cs


示例18: Generate

        /// <summary>
        ///     Generates code to perform an <see cref="AddPrimaryKeyOperation" />.
        /// </summary>
        /// <param name="addPrimaryKeyOperation"> The operation to generate code for. </param>
        /// <param name="writer"> Text writer to add the generated code to. </param>
        protected virtual void Generate(AddPrimaryKeyOperation addPrimaryKeyOperation, IndentedTextWriter writer)
        {
            Check.NotNull(addPrimaryKeyOperation, "addPrimaryKeyOperation");
            Check.NotNull(writer, "writer");

            writer.Write("AddPrimaryKey(");
            writer.Write(Quote(addPrimaryKeyOperation.Table));
            writer.Write(", ");

            var compositeKey = addPrimaryKeyOperation.Columns.Count() > 1;

            if (compositeKey)
            {
                writer.Write("new[] { ");
            }

            writer.Write(addPrimaryKeyOperation.Columns.Join(Quote));

            if (compositeKey)
            {
                writer.Write(" }");
            }

            if (!addPrimaryKeyOperation.HasDefaultName)
            {
                writer.Write(", name: ");
                writer.Write(Quote(addPrimaryKeyOperation.Name));
            }

            writer.WriteLine(");");
        }
开发者ID:hallco978,项目名称:entityframework,代码行数:36,代码来源:CSharpMigrationCodeGenerator.cs


示例19: CreateTableOperation

    /// <summary>
    /// Creates a table named Posts 
    /// and columns int PostId, string Title, string Body 
    /// </summary>
    /// <returns></returns>

    private CreateTableOperation CreateTableOperation()
    {
      TypeUsage tu;
      TypeUsage result;

      if (ProviderManifest == null)
        ProviderManifest = new MySqlProviderManifest(Version.ToString());

      var createTableOperation = new CreateTableOperation("Posts");

      //Column model for int IdPost
      tu = TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32));
      result = ProviderManifest.GetStoreType(tu);

      var intColumn = new ColumnModel(PrimitiveTypeKind.Int32, result)
      {
        Name = "PostId",
        IsNullable = false,
        IsIdentity = true
      };

      createTableOperation.Columns.Add(intColumn);

      //Column model for string 
      tu = TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
      result = ProviderManifest.GetStoreType(tu);

      var stringColumnTitle = new ColumnModel(PrimitiveTypeKind.String, result)
      {
        Name = "Title",
        IsNullable = false
      };

      var stringColumnBody = new ColumnModel(PrimitiveTypeKind.String, result)
      {
        Name = "Body",
        IsNullable = true
      };

      createTableOperation.Columns.Add(stringColumnTitle);
      createTableOperation.Columns.Add(stringColumnBody);
      var primaryKey = new AddPrimaryKeyOperation();

      primaryKey.Columns.Add("PostId");

      createTableOperation.PrimaryKey = primaryKey;
      
      return createTableOperation;
    
    }
开发者ID:eeeee,项目名称:mysql-connector-net,代码行数:56,代码来源:MySqlMigrationsTests.cs


示例20: Generate

		protected override void Generate(AddPrimaryKeyOperation addPrimaryKeyOperation)
		{
			addPrimaryKeyOperation.IsClustered = false;
			base.Generate(addPrimaryKeyOperation);
		}
开发者ID:xbadcode,项目名称:Rubezh,代码行数:5,代码来源:NonClusteredPrimaryKeySqlServerMigrationSqlGenerator.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Model.ColumnModel类代码示例发布时间:2022-05-26
下一篇:
C# Model.AddForeignKeyOperation类代码示例发布时间: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