I have an entity:
public class Section : SortableEntity
{
private ICollection<Section> _sections;
public ICollection<Section> Sections
{
get
{
return _sections ?? (_sections = new HashSet<Section>());
}
set
{
_sections = value;
}
}
public string Title { get; set; }
public string Description { get; set; }
public Section ParentSection { get; set; }
public int? ParentSectionId { get; set; }
}
And on model creating I have a configuration:
modelBuilder.Entity<Section>().HasOptional(x => x.ParentSection).WithMany(p => p.Sections).HasForeignKey(d => d.ParentSectionId);
I'm trying to make a cascade delete and I'm getting a following error: "The DELETE statement conflicted with the SAME TABLE REFERENCE constraint "FK_dbo.Section_dbo.Section_ParentSectionId".
How can I configure cascade delete on self-referencing entity?