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


C# Model.AddForeignKeyOperation类代码示例

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


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

示例1: DropForeignKeyOperation

        public DropForeignKeyOperation(AddForeignKeyOperation inverse, object anonymousArguments = null)
            : base(anonymousArguments)
        {
            Check.NotNull(inverse, "inverse");

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

示例2: Inverse_should_return_add_foreign_key_operation

        public void Inverse_should_return_add_foreign_key_operation()
        {
            var addForeignKeyOperation = new AddForeignKeyOperation();
            var dropForeignKeyOperation = new DropForeignKeyOperation(addForeignKeyOperation);

            Assert.Same(addForeignKeyOperation, dropForeignKeyOperation.Inverse);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:7,代码来源:DropForeignKeyOperationTests.cs

示例3: DropForeignKeyOperation

        public DropForeignKeyOperation(AddForeignKeyOperation inverse, object anonymousArguments = null)
            : base(anonymousArguments)
        {
            //Contract.Requires(inverse != null);

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

示例4: Generate

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

示例5: DefaultName_is_restricted_to_128_chars

        public void DefaultName_is_restricted_to_128_chars()
        {
            var addForeignKeyOperation = new AddForeignKeyOperation
                                             {
                                                 PrincipalTable = "P",
                                                 DependentTable = "D"
                                             };

            addForeignKeyOperation.DependentColumns.Add(new string('c', 150));

            Assert.Equal(128, addForeignKeyOperation.DefaultName.Length);
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:12,代码来源:AddForeignKeyOperationTests.cs

示例6: CreateCreateIndexOperation_should_return_corresponding_create_index_operation

        public void CreateCreateIndexOperation_should_return_corresponding_create_index_operation()
        {
            var addForeignKeyOperation = new AddForeignKeyOperation
                                             {
                                                 PrincipalTable = "P",
                                                 DependentTable = "D",
                                                 Name = "Foo"
                                             };
            addForeignKeyOperation.DependentColumns.Add("fk");

            var createIndexOperation = addForeignKeyOperation.CreateCreateIndexOperation();

            Assert.Equal(createIndexOperation.DefaultName, createIndexOperation.Name);
            Assert.Equal("D", createIndexOperation.Table);
            Assert.Equal("fk", createIndexOperation.Columns.Single());
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:16,代码来源:AddForeignKeyOperationTests.cs

示例7: Inverse_should_produce_drop_foreign_key_operation

        public void Inverse_should_produce_drop_foreign_key_operation()
        {
            var addForeignKeyOperation = new AddForeignKeyOperation
                                             {
                                                 PrincipalTable = "P",
                                                 DependentTable = "D",
                                                 Name = "Foo"
                                             };

            addForeignKeyOperation.PrincipalColumns.Add("pk");
            addForeignKeyOperation.DependentColumns.Add("fk");

            var dropForeignKeyOperation = (DropForeignKeyOperation)addForeignKeyOperation.Inverse;

            Assert.Equal("P", dropForeignKeyOperation.PrincipalTable);
            Assert.Equal("D", dropForeignKeyOperation.DependentTable);
            Assert.Equal("fk", dropForeignKeyOperation.DependentColumns.Single());
            Assert.Equal("Foo", dropForeignKeyOperation.Name);
            Assert.Equal("FK_D_P_fk", dropForeignKeyOperation.DefaultName);
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:20,代码来源:AddForeignKeyOperationTests.cs

示例8: Can_get_and_set_properties

        public void Can_get_and_set_properties()
        {
            var addForeignKeyOperation = new AddForeignKeyOperation
                                             {
                                                 PrincipalTable = "P",
                                                 DependentTable = "D",
                                                 CascadeDelete = true,
                                                 Name = "Foo"
                                             };

            addForeignKeyOperation.PrincipalColumns.Add("pk");
            addForeignKeyOperation.DependentColumns.Add("fk");

            Assert.Equal("P", addForeignKeyOperation.PrincipalTable);
            Assert.Equal("D", addForeignKeyOperation.DependentTable);
            Assert.Equal("pk", addForeignKeyOperation.PrincipalColumns.Single());
            Assert.Equal("fk", addForeignKeyOperation.DependentColumns.Single());
            Assert.True(addForeignKeyOperation.CascadeDelete);
            Assert.Equal("Foo", addForeignKeyOperation.Name);
            Assert.Equal("FK_D_P_fk", addForeignKeyOperation.DefaultName);
            Assert.False(addForeignKeyOperation.HasDefaultName);
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:22,代码来源:AddForeignKeyOperationTests.cs

示例9: CreateDropIndexOperation_should_return_corresponding_drop_index_operation

        public void CreateDropIndexOperation_should_return_corresponding_drop_index_operation()
        {
            var addForeignKeyOperation
                = new AddForeignKeyOperation
                      {
                          DependentTable = "D"
                      };
            addForeignKeyOperation.DependentColumns.Add("fk");

            var dropForeignKeyOperation
                = new DropForeignKeyOperation(addForeignKeyOperation)
                      {
                          DependentTable = "D"
                      };

            dropForeignKeyOperation.DependentColumns.Add("fk");

            var dropIndexOperation = dropForeignKeyOperation.CreateDropIndexOperation();

            Assert.Equal("D", dropIndexOperation.Table);
            Assert.NotNull(dropIndexOperation.Inverse);
            Assert.Equal("fk", dropIndexOperation.Columns.Single());
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:23,代码来源:DropForeignKeyOperationTests.cs

示例10: Generate

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

            using (var writer = Writer())
            {
                writer.Write("ALTER TABLE ");
                writer.Write(Name(addForeignKeyOperation.DependentTable));
                writer.Write(" ADD CONSTRAINT ");
                writer.Write(Quote(addForeignKeyOperation.Name));
                writer.Write(" FOREIGN KEY (");
                writer.Write(addForeignKeyOperation.DependentColumns.Select(Quote).Join());
                writer.Write(") REFERENCES ");
                writer.Write(Name(addForeignKeyOperation.PrincipalTable));
                writer.Write(" (");
                writer.Write(addForeignKeyOperation.PrincipalColumns.Select(Quote).Join());
                writer.Write(")");

                if (addForeignKeyOperation.CascadeDelete)
                {
                    writer.Write(" ON DELETE CASCADE");
                }

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

示例11: Convert

        private void Convert(AddForeignKeyOperation addForeignKeyOperation)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("ALTER TABLE ");
            AppendTableName(addForeignKeyOperation.DependentTable, sql);
            sql.Append(" ADD CONSTRAINT \"");
            sql.Append(addForeignKeyOperation.Name);
            sql.Append("\" FOREIGN KEY (");
            foreach (var column in addForeignKeyOperation.DependentColumns)
            {
                sql.Append('"');
                sql.Append(column);
                sql.Append("\",");
            }
            sql.Remove(sql.Length - 1, 1);
            sql.Append(") REFERENCES ");
            AppendTableName(addForeignKeyOperation.PrincipalTable, sql);
            sql.Append(" (");
            foreach (var column in addForeignKeyOperation.PrincipalColumns)
            {
                sql.Append('"');
                sql.Append(column);
                sql.Append("\",");
            }
            sql.Remove(sql.Length - 1, 1);
            sql.Append(")");

            if (addForeignKeyOperation.CascadeDelete)
            {
                sql.Append(" ON DELETE CASCADE");
            }
            AddStatment(sql);
        }
开发者ID:mono,项目名称:linux-packaging-npgsql,代码行数:33,代码来源:NpgsqlMigrationSqlGenerator.cs

示例12: Generate_can_output_composite_add_foreign_key

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

            var addForeignKeyOperation
                = new AddForeignKeyOperation
                      {
                          DependentTable = "Orders",
                          PrincipalTable = "Customers"
                      };

            addForeignKeyOperation.DependentColumns.Add("CustomerId1");
            addForeignKeyOperation.DependentColumns.Add("CustomerId2");
            addForeignKeyOperation.PrincipalColumns.Add("Id1");
            addForeignKeyOperation.PrincipalColumns.Add("Id2");

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

            Assert.Equal(
                @"namespace Foo
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class Bar : DbMigration
    {
        public override void Up()
        {
            AddForeignKey(""Orders"", new[] { ""CustomerId1"", ""CustomerId2"" }, ""Customers"", new[] { ""Id1"", ""Id2"" });
        }
        
        public override void Down()
        {
            DropForeignKey(""Orders"", new[] { ""CustomerId1"", ""CustomerId2"" }, ""Customers"");
        }
    }
}
",
                generatedMigration.UserCode);
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:47,代码来源:CSharpMigrationCodeGeneratorTests.cs

示例13: Generate

    protected virtual MigrationStatement Generate(AddForeignKeyOperation op)
    {

      StringBuilder sb = new StringBuilder();
      string fkName = op.Name;
      if (fkName.Length > 64)
      {
        fkName = "FK_" + Guid.NewGuid().ToString().Replace("-", "");
      }
      sb.Append("alter table `" + TrimSchemaPrefix(op.DependentTable) + "` add constraint `" + TrimSchemaPrefix(fkName) + "` " +
                 " foreign key ");

      sb.Append("(" + string.Join(",", op.DependentColumns.Select(c => "`" + c + "`")) + ") ");
      sb.Append("references `" + TrimSchemaPrefix(op.PrincipalTable) + "` ( " + string.Join(",", op.PrincipalColumns.Select(c => "`" + c + "`")) + ") ");

      if (op.CascadeDelete)
      {
        sb.Append(" on update cascade on delete cascade ");
      }

      return new MigrationStatement { Sql = sb.ToString() };
    }
开发者ID:betabot7,项目名称:mysql-connector-net,代码行数:22,代码来源:MySqlMigrationSqlGenerator.cs

示例14: GenerateInline

 protected override void GenerateInline(AddForeignKeyOperation addForeignKeyOperation, IndentedTextWriter writer)
 {
   writer.WriteLine();
   writer.Write(".ForeignKey(\"" + TrimSchemaPrefix(addForeignKeyOperation.PrincipalTable) + "\", ");
   Generate(addForeignKeyOperation.DependentColumns, writer);
   writer.Write(addForeignKeyOperation.CascadeDelete ? ", cascadeDelete: true)" : ")");
 }
开发者ID:betabot7,项目名称:mysql-connector-net,代码行数:7,代码来源:MySqlMigrationSqlGenerator.cs

示例15: Generate

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

            writer.Write("AddForeignKey(");
            writer.Write(Quote(addForeignKeyOperation.DependentTable));
            writer.Write(", ");

            var compositeKey = addForeignKeyOperation.DependentColumns.Count() > 1;

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

            writer.Write(addForeignKeyOperation.DependentColumns.Join(Quote));

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

            writer.Write(", ");
            writer.Write(Quote(addForeignKeyOperation.PrincipalTable));

            if (addForeignKeyOperation.PrincipalColumns.Any())
            {
                writer.Write(", ");

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

                writer.Write(addForeignKeyOperation.PrincipalColumns.Join(Quote));

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

            if (addForeignKeyOperation.CascadeDelete)
            {
                writer.Write(", cascadeDelete: true");
            }

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

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


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