Skip to content

Commit

Permalink
Review feedback:
Browse files Browse the repository at this point in the history
- Throw if delayed fixup is left in an invalid state
- Store arguments rather than delegate
  • Loading branch information
ajcvickers committed Dec 8, 2021
1 parent 0375e27 commit 270c09e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/EFCore/ChangeTracking/Internal/NavigationFixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
/// </summary>
public class NavigationFixer : INavigationFixer
{
private IList<Action>? _danglingJoinEntities;
private IList<(
InternalEntityEntry Entry,
InternalEntityEntry OtherEntry,
ISkipNavigation SkipNavigation,
bool FromQuery,
bool SetModified)>? _danglingJoinEntities;

private readonly IEntityGraphAttacher _attacher;
private bool _inFixup;
private bool _inAttachGraph;
Expand Down Expand Up @@ -43,7 +49,11 @@ public virtual bool BeginDelayedFixup()
return false;
}

_danglingJoinEntities?.Clear();
if (_danglingJoinEntities != null)
{
throw new InvalidOperationException(CoreStrings.InvalidDbContext);
}

_inAttachGraph = true;

return true;
Expand All @@ -61,10 +71,10 @@ public virtual void CompleteDelayedFixup()
if (_danglingJoinEntities != null)
{
var dangles = _danglingJoinEntities.ToList();
_danglingJoinEntities.Clear();
foreach (var synthesize in dangles)
_danglingJoinEntities = null;
foreach (var arguments in dangles)
{
synthesize();
FindOrCreateJoinEntry(arguments);
}
}
}
Expand Down Expand Up @@ -1009,9 +1019,15 @@ private void FindOrCreateJoinEntry(
}
else
{
_danglingJoinEntities ??= new List<Action>();

_danglingJoinEntities.Add(() => FindOrCreateJoinEntry(arguments));
_danglingJoinEntities ??=
new List<(
InternalEntityEntry Entry,
InternalEntityEntry OtherEntry,
ISkipNavigation SkipNavigation,
bool FromQuery,
bool SetModified)>();

_danglingJoinEntities.Add(arguments);
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/EFCore/Properties/CoreStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/EFCore/Properties/CoreStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,9 @@
<data name="InvalidAlternateKeyValue" xml:space="preserve">
<value>Unable to track an entity of type '{entityType}' because alternate key property '{keyProperty}' is null. If the alternate key is not used in a relationship, then consider using a unique index instead. Unique indexes may contain nulls, while alternate keys may not.</value>
</data>
<data name="InvalidDbContext" xml:space="preserve">
<value>A previous error has left the DbContext in an invalid state. Applications should not continue to use a DbContext instance after an InvalidOperationException has been thrown.</value>
</data>
<data name="InvalidEntityType" xml:space="preserve">
<value>The specified type '{type}' must be a non-interface reference type to be used as an entity type.</value>
</data>
Expand Down

0 comments on commit 270c09e

Please sign in to comment.