本文整理汇总了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;
}
示例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);
}
示例3: DropForeignKeyOperation
public DropForeignKeyOperation(AddForeignKeyOperation inverse, object anonymousArguments = null)
: base(anonymousArguments)
{
//Contract.Requires(inverse != null);
_inverse = inverse;
}
示例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);
}
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
}
示例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);
}
示例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);
}
示例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() };
}
示例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)" : ")");
}
示例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(");");
}