引入外键约束可能会导致循环或多个级联路径-为什么?
在表“侧”上引入外键约束‘fk_dbo.ides_dbo.Cards_CardId’可能会导致循环或多个级联路径。指定“删除不操作”或“更新不操作”,或修改其他外键约束。
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; }}
public class Side{ public Side() { Stage = Stage.ONE; } [Key] [Required] public virtual int SideId { get; set; } [Required] public virtual Stage Stage { get; set; } [Required] public int CardId { get; set; } [ForeignKey("CardId")] public virtual Card Card { get; set; }}
public class Stage{ // Zero public static readonly Stage ONE = new Stage(new TimeSpan(0, 0, 0), "ONE"); // Ten seconds public static readonly Stage TWO = new Stage(new TimeSpan(0, 0, 10), "TWO"); public static IEnumerable<Stage> Values { get { yield return ONE; yield return TWO; } } public int StageId { get; set; } private readonly TimeSpan span; public string Title { get; set; } Stage(TimeSpan span, string title) { this.span = span; this.Title = title; } public TimeSpan Span { get { return span; } }}
public int? SideId { get; set; } [ForeignKey("SideId")] public virtual Side Side { get; set; }
Stage_StageId
Cards
Sides
Stage
[Required] [ForeignKey("StageId")] public virtual Stage Stage { get; set; } public int StageId { get; set; }
StageId
Side
Stage
SideId
Card
Side
Stage
慕码人2483693
一只名叫tom的猫
牛魔王的故事