为一对主从表增加级联删除功能

protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<HiddenDanger>()
                .HasMany(o => o.HidDangerAttachments)
                .WithRequired(o => o.HiddenDanger)
                .WillCascadeOnDelete();
            base.OnModelCreating(modelBuilder);
        }
//HiddenDanger主表,HidDangerAttachments子表

添加级联删除规则

Entity Framework 级联删除-LMLPHP

04-27 05:08