Skip to content

Commit

Permalink
Add quirk
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers committed Dec 11, 2020
1 parent b706ce6 commit 0100f2d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/EFCore/Internal/ManyToManyLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,20 @@ private IQueryable<TEntity> Query(
? context.Set<TSourceEntity>(_skipNavigation.DeclaringEntityType.Name)
: context.Set<TSourceEntity>();

return queryRoot
var queryable = queryRoot
.AsTracking()
.Where(BuildWhereLambda(loadProperties, new ValueBuffer(keyValues)))
.SelectMany(BuildSelectManyLambda(_skipNavigation))
.NotQuiteInclude(BuildIncludeLambda(_skipNavigation.Inverse, loadProperties, new ValueBuffer(keyValues)))
.AsQueryable();
.SelectMany(BuildSelectManyLambda(_skipNavigation));

var useOldBehavior = AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue23475", out var enabled) && enabled;

return useOldBehavior
? queryable
.Include(BuildIncludeLambda(_skipNavigation.Inverse, loadProperties, new ValueBuffer(keyValues)))
.AsQueryable()
: queryable
.NotQuiteInclude(BuildIncludeLambda(_skipNavigation.Inverse, loadProperties, new ValueBuffer(keyValues)))
.AsQueryable();
}

private static Expression<Func<TEntity, IEnumerable<TSourceEntity>>> BuildIncludeLambda(
Expand Down
4 changes: 3 additions & 1 deletion src/EFCore/Query/IncludeExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public IncludeExpression(
NavigationExpression = navigationExpression;
Navigation = navigation;
Type = EntityExpression.Type;
SetLoaded = setLoaded;

var useOldBehavior = AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue23475", out var enabled) && enabled;
SetLoaded = useOldBehavior || setLoaded;
}

/// <summary>
Expand Down

0 comments on commit 0100f2d

Please sign in to comment.