本文介绍了指定父级/子级关系的级联删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
型号:
public class MenuItem
{
public Guid Id {get;set;}
public virtual Guid? ParentMenuItemId {get;set;}
public virtual MenuItem ParentMenuItem {get;set;}
public virtual ICollection<MenuItem> ChildMenuItems {get;set;}
}
当前映射:
HasOptional(m => m.ParentMenuItem).WithMany(p => p.ChildMenuItems).HasForeignKey(m => m.ParentMenuItemId);
我尝试添加WillCascadeOnDelete(true)
,但是出现错误.如何更新我的映射以允许级联删除?因此,如果我删除了父母,所有的孩子都将被删除.我必须手动执行此操作吗?
I tried adding the WillCascadeOnDelete(true)
, but I got an error. How should I update my mapping to allow for cascading deletes? So, If I delete a Parent, all the children will be deleted. Do I have to do this manually?
推荐答案
在模型中,只需查看关联的属性即可.您可以将OnDelete设置为Cascade. XML应该如下所示:
In your model, just look at the association's properties. There is an OnDelete that you can set to Cascade. The XML should look like this:
<OnDelete Action="Cascade" />
这篇关于指定父级/子级关系的级联删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!