我有两节课:
public class Cluster
{
public int Id { get; set; }
public virtual ICollection<Blob> Blobs { get; set; }
}
public class Blob
{
public int Id { get; set; }
public virtual ICollection<Cluster> Clusters { get; set; }
}
public ClusterConfiguration ()
{
this.HasKey(p => p.Id)
.HasRequired(p => p.Frame)
.WithMany(p => p.Clusters)
.HasForeignKey(p => p.FrameId)
.WillCascadeOnDelete(true)
;
this.HasMany(p => p.Blobs)
.WithMany(p => p.Clusters)
;
}
public BlobConfiguration ()
{
this.HasKey(p => p.Id)
.HasRequired(p => p.Frame)
.WithMany(p => p.Blobs)
.HasForeignKey(p => p.FrameId)
.WillCascadeOnDelete(true)
;
this.HasMany(p => p.Clusters)
.WithMany(p => p.Blobs)
;
}
这些类中有对其他表的引用,但我认为这不是问题。错误是:
[{"Introducing FOREIGN KEY constraint 'FK_dbo.ClusterBlobs_dbo.Blob_Blob_Id' on table 'ClusterBlobs' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.\r\nCould not create constraint. See previous errors."}].
我不太确定如何告诉 EF 如果删除集群则级联删除 Blob,但如果删除 Blob,则不删除集群。请指教。
更新:顺便使用 EF5。