我有一个Page
要与类似页面关联的类。每个关联都有关于该关联的附加信息。这是已定义为 a 表示的类Page
。
public class Page {
[Key]
public virtual int Id { get; protected set; }
[Required]
[StringLength(32)]
public virtual string Name { get; set; }
[InverseProperty("Page")]
public virtual ICollection<Association> Associations { get; set; }
}
每个页面都可以与任意数量的其他页面相关联。这将被定义为源页面和目标页面。我不介意关联是单向的还是双向的,在我的特定场景中都是合理的(我更喜欢双向关联,很难)。这是关联类..
public class Association {
[Key, Column(Order = 0)]
public virtual int PageId { get; protected set; } // SOURCE
[Required]
public virtual Page Page { get; set; } // SOURCE
[Key, Column(Order = 1)]
public virtual int TargetId { get; protected set; } // TARGET
[Required]
public virtual Page Target { get; set; } // TARGET
[Required]
[StringLength(32)]
public virtual string InformationAboutTheAssociation { get; set; }
}
现在我有以下上下文......
public class DbCtx : DbContext {
public DbSet<Association> Associations { get; set; }
public DbSet<Page> Pages { get; set; }
}
问题是 SQL Express 抱怨可能的循环引用(事实并非如此,但它是过度保护的)。如何解决为接受所描述的场景而生成的方案?
Introducing FOREIGN KEY constraint 'FK_dbo.Associations_dbo.Pages_TargetId' on table 'Associations' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
谢谢!