EF6多对多,WillCascadeOnDelete和多个级联路径

Mau*_*Mau 5 .net c# database-design entity-framework

在EF6 CodeFirst中,我想用导航属性建模多对多关系.

课程:

public class Event
{
    [DataMember]
    [Required]
    public int Id { get; set; }

    // Other properties

    [DataMember]
    public virtual ICollection<Notification> Notifications { get; set; }
}

public class Notification
{
    [DataMember]
    [Required]
    public int Id { get; set; }

    // Other properties

    [DataMember]
    public virtual ICollection<Event> Events { get; set; }
}

class EventConfiguration : EntityTypeConfiguration<Event>
{
    public EventConfiguration()
    {
        HasMany(e => e.Notifications)
            .WithMany(e => e.Events)
            .Map(m => m.ToTable("NotificationEvents"));
    }
}
Run Code Online (Sandbox Code Playgroud)

有级联删除上EventNotification 从其它表.

如果我尝试创建数据库,我得到:

在表'NotificationEvents'上引入FOREIGN KEY约束'FK_dbo.NotificationEvents_dbo.Events_Event_Id'可能会导致循环或多个级联路径.指定ON DELETE NO ACTION或ON UPDATE NO ACTION,或修改其他FOREIGN KEY约束.

考虑到其他级联,这是公平的.现在我的问题是:如何(或我可以)在这种关系的一方或双方都没有指定级联?

如果我添加(如另一篇文章所示):

class NotificationConfiguration : EntityTypeConfiguration<Notification>
{
    public NotificationConfiguration()
    {
        HasOptional(e => e.Events).WithMany().WillCascadeOnDelete(false);
    }
}
Run Code Online (Sandbox Code Playgroud)

我明白了:

在"通知"类型上声明的导航属性"事件"已配置有冲突的多重性.