Skip to content

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

Merged
ajcvickers merged 2 commits intorelease/7.0from
JengaForDbas0902
Sep 2, 2022
Merged

Don't skip creating cascade delete on SQL Server when types are base-linking across tables#28965
ajcvickers merged 2 commits intorelease/7.0from
JengaForDbas0902

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.


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