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

[6.0.2] Detach join entity when removing added relationship #26892

Merged
merged 1 commit into from
Dec 15, 2021
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
10 changes: 9 additions & 1 deletion src/EFCore/ChangeTracking/Internal/NavigationFixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class NavigationFixer : INavigationFixer
private bool _inFixup;
private bool _inAttachGraph;

private readonly bool _useOldBehavior26779
= AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue26779", 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 @@ -294,7 +297,12 @@ public virtual void NavigationCollectionChanged(

if (navigationBase is ISkipNavigation skipNavigation)
{
FindJoinEntry(entry, oldTargetEntry, skipNavigation)?.SetEntityState(EntityState.Deleted);
var joinEntry = FindJoinEntry(entry, oldTargetEntry, skipNavigation);

joinEntry?.SetEntityState(
_useOldBehavior26779 || joinEntry.EntityState != EntityState.Added
? EntityState.Deleted
: EntityState.Detached);

Check.DebugAssert(
skipNavigation.Inverse.IsCollection,
Expand Down
Loading