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

Don't skip creating cascade delete on SQL Server when types are base-linking across tables #28965

Merged
merged 2 commits into from
Sep 2, 2022

Conversation

ajcvickers
Copy link
Contributor

E.g. for TPT.

Fixes #28532 (Cascade delete behavior for FK between PKs in TPT)

Note this is a breaking change--creating a cascade delete for the TPT relationship could cause a cycle with another existing cascade relationship. This is what happened with the GearsOfWar model.

@@ -57,7 +57,8 @@ protected override DeleteBehavior GetTargetDeleteBehavior(IConventionForeignKey
return deleteBehavior;
}

if (foreignKey.IsBaseLinking())
if (foreignKey.IsBaseLinking()
&& IsMappedToSameTable(foreignKey.DeclaringEntityType, foreignKey.PrincipalEntityType))
Copy link
Member

@AndriySvyryd AndriySvyryd Sep 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Base linking FKs on the same table wouldn't be created in the database, since they are redundant, so we can just remove this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remove this, then "Entity_splitting_is_stored_in_snapshot_with_tables" fails. Not sure what the correct behavior should be for entity splitting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

                    b.HasOne(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Order"", null)
                        .WithOne()
                        .HasForeignKey(""Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Order"", ""Id"")
                        .OnDelete(DeleteBehavior.ClientCascade)
                        .IsRequired();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be Cascade too

@ajcvickers
Copy link
Contributor Author

@AndriySvyryd Updated.

…linking across tables

E.g. for TPT.

Fixes #28532 (Cascade delete behavior for FK between PKs in TPT)

Note this is a breaking change--creating a cascade delete for the TPT relationship could cause a cycle with another existing cascade relationship. This is what happened with the GearsOfWar model.
@ajcvickers ajcvickers merged commit bf62eaf into release/7.0 Sep 2, 2022
@ajcvickers ajcvickers deleted the JengaForDbas0902 branch September 2, 2022 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cascade delete behavior for FK between PKs in TPT
2 participants