本文整理汇总了C#中System.Data.Entity.Migrations.Model.AddForeignKeyOperation类的典型用法代码示例。如果您正苦于以下问题:C# AddForeignKeyOperation类的具体用法?C# AddForeignKeyOperation怎么用?C# AddForeignKeyOperation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AddForeignKeyOperation类属于System.Data.Entity.Migrations.Model命名空间,在下文中一共展示了AddForeignKeyOperation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: Generate_can_output_composite_add_foreign_key
public void Generate_can_output_composite_add_foreign_key()
{
var codeGenerator = new VisualBasicMigrationCodeGenerator();
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(
@"Imports System
Imports System.Data.Entity.Migrations
Namespace Foo
Public Partial Class Bar
Inherits DbMigration
Public Overrides Sub Up()
AddForeignKey(""Orders"", New String() { ""CustomerId1"", ""CustomerId2"" }, ""Customers"", New String() { ""Id1"", ""Id2"" })
End Sub
Public Overrides Sub Down()
DropForeignKey(""Orders"", New String() { ""CustomerId1"", ""CustomerId2"" }, ""Customers"")
End Sub
End Class
End Namespace
",
generatedMigration.UserCode);
}
开发者ID:junxy,项目名称:entityframework,代码行数:45,代码来源:VisualBasicMigrationCodeGeneratorTests.cs
示例17: Generate
protected virtual MigrationStatement Generate(AddForeignKeyOperation op)
{
StringBuilder sb = new StringBuilder();
sb.Append("alter table `" + op.DependentTable + "` add constraint `" + op.Name + "` " +
" foreign key ");
sb.Append("(" + string.Join(",", op.DependentColumns.Select(c => "`" + c + "`")) + ") ");
sb.Append("references `" + 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:schivei,项目名称:mysql-connector-net,代码行数:16,代码来源:MySqlMigrationSqlGenerator.cs
示例18: CreateForeignKeyOperation
public void CreateForeignKeyOperation()
{
var migrationOperations = new List<MigrationOperation>();
// create dependant table Posts
var createTableOperation = CreateTableOperation();
migrationOperations.Add(createTableOperation);
// Add column BlogId to create the constraints
if (ProviderManifest == null)
ProviderManifest = new MySqlProviderManifest(Version.ToString());
TypeUsage tu = TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32));
TypeUsage result = ProviderManifest.GetStoreType(tu);
var intColumn = new ColumnModel(PrimitiveTypeKind.Int32, result)
{
Name = "BlogId",
IsNullable = false
};
var addColumnMigratioOperation = new AddColumnOperation("Posts", intColumn);
migrationOperations.Add(addColumnMigratioOperation);
// create constrain object
var createForeignkeyOperation = new AddForeignKeyOperation();
createForeignkeyOperation.Name = "FKBlogs";
createForeignkeyOperation.DependentTable = "Posts";
createForeignkeyOperation.DependentColumns.Add("BlogId");
createForeignkeyOperation.CascadeDelete = true;
createForeignkeyOperation.PrincipalTable = "Blogs";
createForeignkeyOperation.PrincipalColumns.Add("BlogId");
//create index to use
migrationOperations.Add(createForeignkeyOperation.CreateCreateIndexOperation());
migrationOperations.Add(createForeignkeyOperation);
using (BlogContext context = new BlogContext())
{
if (context.Database.Exists()) context.Database.Delete();
context.Database.Create();
Assert.AreEqual(true, GenerateAndExecuteMySQLStatements(migrationOperations));
using (var conn = new MySqlConnection(context.Database.Connection.ConnectionString))
{
if (conn.State == System.Data.ConnectionState.Closed) conn.Open();
// check for foreign key creation
MySqlCommand query = new MySqlCommand("select Count(*) from information_schema.table_constraints where constraint_type = 'foreign key' and constraint_schema = '" + conn.Database + "' and constraint_name = 'FKBlogs'", conn);
int rows = Convert.ToInt32(query.ExecuteScalar());
Assert.AreEqual(1, rows);
// check for table creation
query = new MySqlCommand("select Count(*) from information_schema.Tables WHERE `table_name` = 'Posts' and `table_schema` = '" + conn.Database + "' ", conn);
rows = Convert.ToInt32(query.ExecuteScalar());
Assert.AreEqual(1, rows);
conn.Close();
}
// Test fix for
MySqlConnection con = GetConnectionFromContext(context);
con.Open();
try
{
MySqlCommand cmd = new MySqlCommand("show create table `posts`", con);
using (MySqlDataReader r = cmd.ExecuteReader())
{
r.Read();
string sql = r.GetString(1);
Assert.IsTrue(sql.IndexOf(
" CONSTRAINT `FKBlogs` FOREIGN KEY (`BlogId`) REFERENCES `blogs` (`BlogId`) ON DELETE CASCADE ON UPDATE CASCADE",
StringComparison.OrdinalIgnoreCase) != -1);
}
}
finally
{
con.Close();
}
}
}
开发者ID:schivei,项目名称:mysql-connector-net,代码行数:83,代码来源:MySqlMigrationsTests.cs
示例19: CreateForeignKeyOperation
public void CreateForeignKeyOperation()
{
var migrationOperations = new List<MigrationOperation>();
// create dependant table Posts
var createTableOperation = CreateTableOperation();
migrationOperations.Add(createTableOperation);
// Add column BlogId to create the constraints
if (ProviderManifest == null)
ProviderManifest = new MySqlProviderManifest(Version.ToString());
TypeUsage tu = TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32));
TypeUsage result = ProviderManifest.GetStoreType(tu);
var intColumn = new ColumnModel(PrimitiveTypeKind.Int32, result)
{
Name = "BlogId",
IsNullable = false
};
var addColumnMigratioOperation = new AddColumnOperation("Posts", intColumn);
migrationOperations.Add(addColumnMigratioOperation);
// create constrain object
var createForeignkeyOperation = new AddForeignKeyOperation();
createForeignkeyOperation.Name = "FKBlogs";
createForeignkeyOperation.DependentTable = "Posts";
createForeignkeyOperation.DependentColumns.Add("BlogId");
createForeignkeyOperation.CascadeDelete = true;
createForeignkeyOperation.PrincipalTable = "Blogs";
createForeignkeyOperation.PrincipalColumns.Add("BlogId");
//create index to use
migrationOperations.Add(createForeignkeyOperation.CreateCreateIndexOperation());
migrationOperations.Add(createForeignkeyOperation);
using (BlogContext context = new BlogContext())
{
if (context.Database.Exists()) context.Database.Delete();
context.Database.Create();
Assert.AreEqual(true, GenerateAndExecuteMySQLStatements(migrationOperations));
using (var conn = new MySqlConnection(context.Database.Connection.ConnectionString))
{
if (conn.State == System.Data.ConnectionState.Closed) conn.Open();
// check for foreign key creation
MySqlCommand query = new MySqlCommand("select Count(*) from information_schema.table_constraints where constraint_type = 'foreign key' and constraint_schema = '" + conn.Database + "' and constraint_name = 'FKBlogs'", conn);
int rows = Convert.ToInt32(query.ExecuteScalar());
Assert.AreEqual(1, rows);
// check for table creation
query = new MySqlCommand("select Count(*) from information_schema.Tables WHERE `table_name` = 'Posts' and `table_schema` = '" + conn.Database + "' ", conn);
rows = Convert.ToInt32(query.ExecuteScalar());
Assert.AreEqual(1, rows);
conn.Close();
}
}
}
开发者ID:eeeee,项目名称:mysql-connector-net,代码行数:65,代码来源:MySqlMigrationsTests.cs
示例20: GenerateInline
/// <summary>
/// Generates code to perform an <see cref="AddForeignKeyOperation" /> as part of a <see cref="CreateTableOperation" />.
/// </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 GenerateInline(AddForeignKeyOperation addForeignKeyOperation, IndentedTextWriter writer)
{
Check.NotNull(addForeignKeyOperation, "addForeignKeyOperation");
Check.NotNull(writer, "writer");
writer.WriteLine(" _");
writer.Write(".ForeignKey(" + Quote(addForeignKeyOperation.PrincipalTable) + ", ");
Generate(addForeignKeyOperation.DependentColumns, writer);
if (addForeignKeyOperation.CascadeDelete)
{
writer.Write(", cascadeDelete := True");
}
writer.Write(")");
}
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:21,代码来源:VisualBasicMigrationCodeGenerator.cs
注:本文中的System.Data.Entity.Migrations.Model.AddForeignKeyOperation类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论