Skip to content

Commit

Permalink
[6.0.2] Detach join entity when removing added relationship (#26892)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers authored Dec 15, 2021
1 parent f8020cb commit b3478b6
Show file tree
Hide file tree
Showing 2 changed files with 910 additions and 1 deletion.
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

0 comments on commit b3478b6

Please sign in to comment.