I'm attempting to set Entity Framework to cascade on delete with an optional foreign key. I'm using code first, and my model looks like this:
public class Node
{
[Key]
public int ID { get; set; }
[ForeignKey("Parent")]
public int? ParentID { get; set; }
public virtual Node Parent { get; set; }
}
I've seen plenty of solutions that suggest, "Just make the foreign key required," but this will not work for me because the parent node may be null.
Does a solution exist that doesn't involve manually deleting child nodes before parent nodes?