Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error configuring cascade delete on self referenced model #8903

Closed
helderboone opened this issue Jun 19, 2017 · 1 comment
Closed

Error configuring cascade delete on self referenced model #8903

helderboone opened this issue Jun 19, 2017 · 1 comment

Comments

@helderboone
Copy link

helderboone commented Jun 19, 2017

public class Foo
    {
        public int Id { get; set; }           

        public virtual Foo Parent { get; set; }

        public int? ParentId { get; set; }

        public virtual ICollection<Foo> Branches { get; set; }
    }

Hi! I'm trying to configure a self referenced model to cascade delete when deleting its parent. I have tried configuring in this two ways:

builder.HasMany(a => a.Branches)
                   .WithOne(a => a.Parent)
                   .HasForeignKey(a => a.ParentId)
                   .OnDelete(DeleteBehavior.Cascade);
            builder.HasMany(a => a.Branches)
                   .WithOne(a => a.Parent)
                   .OnDelete(DeleteBehavior.Cascade);

However both configs are throwing Foreign key constraint 'FK_Foo_Foo_ParentId' on table 'Foo' may cause cycles or multiple cascade paths when I try to update the database.

@ajcvickers
Copy link
Member

This is a SQL Server limitation. See #6956 (comment) for more info.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants