Entity Framework 6 Removing the cadastral code of the first code in a self-referencing object

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 when creating the model, I have a configuration:

modelBuilder.Entity<Section>().HasOptional(x => x.ParentSection).WithMany(p => p.Sections).HasForeignKey(d => d.ParentSectionId);

I am trying to do a cascading delete, and I get the following error: "The DELETE statement was contrary to the SAME TABLE REFERENCE restriction" FK_dbo.Section_dbo.Section_ParentSectionId ".

How to configure cascading deletion in a self-regulatory entity?

+4
source share
1 answer

Google , , ​​ , , SQL Server , , . , , , , - , , , . , , , , . , , . , .

+4

Source: https://habr.com/ru/post/1533678/


All Articles