有没有办法在 Fluent API on Model Mapping 或 ModelBuilder Conventions/Annotations 中生成下面的 ForeignKey?我正在使用EF6。
创建迁移后,我能够手动创建所需的外键更改!按预期工作......但我需要为一些外键创建一个自动化过程!
.ForeignKey("dbo.Client", t => new { t.ClientId, t.CompanyId }, cascadeDelete: false)
整个迁移:
public override void Up()
{
CreateTable(
"dbo.Orders",
c => new
{
Id = c.Int(nullable: false, identity: true),
CompanyId = c.Int(nullable: false),
ClientId = c.Int(nullable: false),
Desc = c.String(maxLength: 80)
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.Company", t => t.CompanyId, cascadeDelete: false)
.ForeignKey("dbo.Client", t => new { t.ClientId, t.CompanyId }, cascadeDelete: false)
.Index(t => t.CompanyId)
.Index(t => t.ClientId);
}