我已经和它搏斗了一段时间,并且无法弄清楚发生了什么.我有一个卡片实体,其中包含Sides(通常为2个) - 卡片和侧面都有一个舞台.我正在使用EF Codefirst迁移,并且迁移失败并出现此错误:
在表'Sides'上引入FOREIGN KEY约束'FK_dbo.Sides_dbo.Cards_CardId'可能会导致循环或多个级联路径.指定ON DELETE NO ACTION或ON UPDATE NO ACTION,或修改其他FOREIGN KEY约束.
这是我的卡片实体:
public class Card
{
public Card()
{
Sides = new Collection<Side>();
Stage = Stage.ONE;
}
[Key]
[Required]
public virtual int CardId { get; set; }
[Required]
public virtual Stage Stage { get; set; }
[Required]
[ForeignKey("CardId")]
public virtual ICollection<Side> Sides { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是我的Side实体:
public class Side
{
public Side()
{
Stage = Stage.ONE;
}
[Key]
[Required]
public virtual int …
Run Code Online (Sandbox Code Playgroud) 我正在运行efcore 2.0.1.
我有一个模特:
public class BigAwesomeDinosaurWithTeeth
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
public ICollection<YummyPunyPrey> YummyPunyPrey { get; set; }
}
public class YummyPunyPrey
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
public Guid? BigAwesomeDinosaurWithTeethId { get; set; }
[ForeignKey("BigAwesomeDinosaurWithTeethId")]
public BigAwesomeDinosaurWithTeeth BigAwesomeDinosaurWithTeeth { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我对这两个课程没有流利的api.但是当我生成迁移时
constraints: table =>
{
table.PrimaryKey("PK_YummyPunyPrey", x => x.Id);
table.ForeignKey(
name: "FK_YummyPunyPrey_BigAwesomeDinosaurWithTeeth_BigAwesomeDinosaurWithTeethId",
column: x => x.BigAwesomeDinosaurWithTeethId,
principalTable: "BigAwesomeDinosaurWithTeeth",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
Run Code Online (Sandbox Code Playgroud)
为什么它生成onDelete:ReferentialAction.Restrict当文档说它应该作为ClientSetNull …
entity-framework ef-code-first entity-framework-core ef-core-2.0