Skip to content

Commit 212ced1

Browse files
committed
Fix OPENJSON postprocessing with split query (dotnet#32978)
Fixes dotnet#32976 (cherry picked from commit 451514e)
1 parent 23e4ab1 commit 212ced1

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/EFCore.SqlServer/Query/Internal/SqlServerJsonPostprocessor.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ private readonly
3232

3333
private RelationalTypeMapping? _nvarcharMaxTypeMapping;
3434

35+
private static readonly bool UseOldBehavior32976 =
36+
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue32976", out var enabled32976) && enabled32976;
37+
3538
/// <summary>
3639
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
3740
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
@@ -70,7 +73,14 @@ public virtual Expression Process(Expression expression)
7073
switch (expression)
7174
{
7275
case ShapedQueryExpression shapedQueryExpression:
73-
return shapedQueryExpression.UpdateQueryExpression(Visit(shapedQueryExpression.QueryExpression));
76+
shapedQueryExpression = shapedQueryExpression.UpdateQueryExpression(Visit(shapedQueryExpression.QueryExpression));
77+
78+
if (!UseOldBehavior32976)
79+
{
80+
shapedQueryExpression = shapedQueryExpression.UpdateShaperExpression(Visit(shapedQueryExpression.ShaperExpression));
81+
}
82+
83+
return shapedQueryExpression;
7484

7585
case SelectExpression selectExpression:
7686
{

test/EFCore.SqlServer.FunctionalTests/Query/NonSharedPrimitiveCollectionsQuerySqlServerTest.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,42 @@ public virtual async Task Same_collection_with_conflicting_type_mappings_not_sup
871871

872872
#endregion Type mapping inference
873873

874+
[ConditionalFact]
875+
public virtual async Task Ordered_collection_with_split_query()
876+
{
877+
var contextFactory = await InitializeAsync<Context32976>(
878+
onModelCreating: mb => mb.Entity<Context32976.Principal>(),
879+
seed: context =>
880+
{
881+
context.Add(new Context32976.Principal { Ints = [2, 3, 4]});
882+
context.SaveChanges();
883+
});
884+
885+
await using var context = contextFactory.CreateContext();
886+
887+
_ = await context.Set<Context32976.Principal>()
888+
.Where(p => p.Ints.Skip(1).Contains(3))
889+
.Include(p => p.Dependents)
890+
.AsSplitQuery()
891+
.SingleAsync();
892+
}
893+
894+
public class Context32976(DbContextOptions options) : DbContext(options)
895+
{
896+
public class Principal
897+
{
898+
public int Id { get; set; }
899+
public List<int> Ints { get; set; }
900+
public List<Dependent> Dependents { get; set; }
901+
}
902+
903+
public class Dependent
904+
{
905+
public int Id { get; set; }
906+
public Principal Principal { get; set; }
907+
}
908+
}
909+
874910
[ConditionalFact]
875911
public virtual void Check_all_tests_overridden()
876912
=> TestHelpers.AssertAllMethodsOverridden(GetType());

0 commit comments

Comments
 (0)