Skip to content

Commit

Permalink
Fix OPENJSON postprocessing with split query (dotnet#32978)
Browse files Browse the repository at this point in the history
Fixes dotnet#32976

(cherry picked from commit 451514e)
  • Loading branch information
roji committed Feb 7, 2024
1 parent 23e4ab1 commit 212ced1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ private readonly

private RelationalTypeMapping? _nvarcharMaxTypeMapping;

private static readonly bool UseOldBehavior32976 =
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue32976", out var enabled32976) && enabled32976;

/// <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 @@ -70,7 +73,14 @@ public virtual Expression Process(Expression expression)
switch (expression)
{
case ShapedQueryExpression shapedQueryExpression:
return shapedQueryExpression.UpdateQueryExpression(Visit(shapedQueryExpression.QueryExpression));
shapedQueryExpression = shapedQueryExpression.UpdateQueryExpression(Visit(shapedQueryExpression.QueryExpression));

if (!UseOldBehavior32976)
{
shapedQueryExpression = shapedQueryExpression.UpdateShaperExpression(Visit(shapedQueryExpression.ShaperExpression));
}

return shapedQueryExpression;

case SelectExpression selectExpression:
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,42 @@ public virtual async Task Same_collection_with_conflicting_type_mappings_not_sup

#endregion Type mapping inference

[ConditionalFact]
public virtual async Task Ordered_collection_with_split_query()
{
var contextFactory = await InitializeAsync<Context32976>(
onModelCreating: mb => mb.Entity<Context32976.Principal>(),
seed: context =>
{
context.Add(new Context32976.Principal { Ints = [2, 3, 4]});
context.SaveChanges();
});

await using var context = contextFactory.CreateContext();

_ = await context.Set<Context32976.Principal>()
.Where(p => p.Ints.Skip(1).Contains(3))
.Include(p => p.Dependents)
.AsSplitQuery()
.SingleAsync();
}

public class Context32976(DbContextOptions options) : DbContext(options)
{
public class Principal
{
public int Id { get; set; }
public List<int> Ints { get; set; }
public List<Dependent> Dependents { get; set; }
}

public class Dependent
{
public int Id { get; set; }
public Principal Principal { get; set; }
}
}

[ConditionalFact]
public virtual void Check_all_tests_overridden()
=> TestHelpers.AssertAllMethodsOverridden(GetType());
Expand Down

0 comments on commit 212ced1

Please sign in to comment.