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

[release/6.0] Revert change to delete dependent when optional FK with cascade delete is set to null #27216

Merged
merged 1 commit into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/EFCore/ChangeTracking/Internal/NavigationFixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class NavigationFixer : INavigationFixer
private readonly bool _useOldBehavior26779
= AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue26779", out var enabled) && enabled;

private readonly bool _useOldBehavior27174
= AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue27174", out var enabled) && enabled;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
Expand Down Expand Up @@ -504,6 +507,8 @@ var targetDependentEntry
}

if (newValue == null
&& (foreignKey.IsRequired
|| _useOldBehavior27174)
&& (foreignKey.DeleteBehavior == DeleteBehavior.Cascade
|| foreignKey.DeleteBehavior == DeleteBehavior.ClientCascade))
{
Expand Down
11 changes: 8 additions & 3 deletions test/EFCore.Tests/ChangeTracking/ChangeTrackerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1943,7 +1943,7 @@ public void Dependent_FKs_are_not_nulled_when_principal_is_detached(bool delayCa
}
}

[ConditionalTheory] // Issues #16546 #25360
[ConditionalTheory] // Issues #16546 #25360; Change reverted in #27174.
[InlineData(false, false, false, true, false)]
[InlineData(true, false, false, true, false)]
[InlineData(false, true, false, true, false)]
Expand Down Expand Up @@ -2043,7 +2043,8 @@ public void Optional_relationship_with_cascade_still_cascades(
Assert.Equal(EntityState.Unchanged, context.Entry(attachedContainer).State);
Assert.Equal(EntityState.Unchanged, context.Entry(attachedTroduct).State);

if (delayCascade)
if (delayCascade
|| (useForeignKey && setProperty))
{
Assert.Equal(EntityState.Modified, context.Entry(attachedRoom).State);
}
Expand All @@ -2058,7 +2059,11 @@ public void Optional_relationship_with_cascade_still_cascades(
Assert.Equal(3, context.ChangeTracker.Entries().Count());
Assert.Equal(EntityState.Unchanged, context.Entry(attachedContainer).State);
Assert.Equal(EntityState.Unchanged, context.Entry(attachedTroduct).State);
Assert.Equal(EntityState.Deleted, context.Entry(attachedRoom).State);


Assert.Equal(
useForeignKey && setProperty ? EntityState.Modified : EntityState.Deleted,
context.Entry(attachedRoom).State);

context.SaveChanges();
}
Expand Down