-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Conversation
@@ -57,7 +57,8 @@ protected override DeleteBehavior GetTargetDeleteBehavior(IConventionForeignKey | |||
return deleteBehavior; | |||
} | |||
|
|||
if (foreignKey.IsBaseLinking()) | |||
if (foreignKey.IsBaseLinking() | |||
&& IsMappedToSameTable(foreignKey.DeclaringEntityType, foreignKey.PrincipalEntityType)) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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();
There was a problem hiding this comment.
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
@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.
76fe355
to
375b789
Compare
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.