Skip to content

Commit

Permalink
Don't fixup to deleted entities (#29133)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers committed Sep 19, 2022
1 parent 5f8e7e9 commit 4e1686a
Show file tree
Hide file tree
Showing 7 changed files with 1,353 additions and 335 deletions.
6 changes: 4 additions & 2 deletions src/EFCore/ChangeTracking/Internal/NavigationFixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,8 @@ private void InitialFixup(
if (foreignKey.IsUnique)
{
var dependentEntry = (InternalEntityEntry?)dependents.FirstOrDefault();
if (dependentEntry != null)
if (dependentEntry != null
&& dependentEntry.EntityState != EntityState.Deleted)
{
var toDependent = foreignKey.PrincipalToDependent;
if (CanOverrideCurrentValue(entry, toDependent, dependentEntry, fromQuery)
Expand All @@ -796,7 +797,8 @@ private void InitialFixup(
{
foreach (InternalEntityEntry dependentEntry in dependents)
{
if (!IsAmbiguous(dependentEntry)
if (dependentEntry.EntityState != EntityState.Deleted
&& !IsAmbiguous(dependentEntry)
&& (!fromQuery || CanOverrideCurrentValue(dependentEntry, foreignKey.DependentToPrincipal, entry, fromQuery)))
{
SetNavigation(dependentEntry, foreignKey.DependentToPrincipal, entry, fromQuery);
Expand Down
Loading

0 comments on commit 4e1686a

Please sign in to comment.