Skip to content

Commit 3a2549b

Browse files
committed
Correct VisitUnary operand evaluation in funcletizer
Fixes #35152
1 parent 664e3bd commit 3a2549b

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,14 +1556,11 @@ UnaryExpression EvaluateOperand(UnaryExpression unary, Expression operand, State
15561556
operand = ProcessEvaluatableRoot(operand, ref operandState);
15571557
}
15581558

1559-
if (_state.ContainsEvaluatable)
1560-
{
1561-
_state = _calculatingPath
1562-
? State.CreateContainsEvaluatable(
1563-
typeof(UnaryExpression),
1564-
[_state.Path! with { PathFromParent = static e => Property(e, nameof(UnaryExpression.Operand)) }])
1565-
: State.NoEvaluatability;
1566-
}
1559+
_state = operandState.ContainsEvaluatable && _calculatingPath
1560+
? State.CreateContainsEvaluatable(
1561+
typeof(UnaryExpression),
1562+
[_state.Path! with { PathFromParent = static e => Property(e, nameof(UnaryExpression.Operand)) }])
1563+
: State.NoEvaluatability;
15671564

15681565
return unary.Update(operand);
15691566
}

test/EFCore.Cosmos.FunctionalTests/Query/NorthwindMiscellaneousQueryCosmosTest.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5325,6 +5325,17 @@ public override async Task Column_access_inside_subquery_predicate(bool async)
53255325
AssertSql();
53265326
}
53275327

5328+
public override async Task Cast_to_object_over_parameter_directly_in_lambda(bool async)
5329+
{
5330+
// Sync always throws before getting to exception being tested.
5331+
if (async)
5332+
{
5333+
// Cosmos doesn't support ORDER BY over parameter/constant:
5334+
// Unsupported ORDER BY clause. ORDER BY item expression could not be mapped to a document path.
5335+
await Assert.ThrowsAsync<CosmosException>(() => base.Cast_to_object_over_parameter_directly_in_lambda(async: true));
5336+
}
5337+
}
5338+
53285339
private void AssertSql(params string[] expected)
53295340
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);
53305341

test/EFCore.Specification.Tests/Query/NorthwindMiscellaneousQueryTestBase.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5897,4 +5897,15 @@ public virtual Task Column_access_inside_subquery_predicate(bool async)
58975897
=> AssertQuery(
58985898
async,
58995899
ss => ss.Set<Customer>().Where(c => ss.Set<Order>().Where(o => c.CustomerID == "ALFKI").Any()));
5900+
5901+
[ConditionalTheory] // #35152
5902+
[MemberData(nameof(IsAsyncData))]
5903+
public virtual Task Cast_to_object_over_parameter_directly_in_lambda(bool async)
5904+
{
5905+
var i = 8;
5906+
5907+
return AssertQuery(
5908+
async,
5909+
ss => ss.Set<Order>().OrderBy(o => (object)i).Select(o => o));
5910+
}
59005911
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7531,6 +7531,17 @@ FROM [Orders] AS [o]
75317531
""");
75327532
}
75337533

7534+
public override async Task Cast_to_object_over_parameter_directly_in_lambda(bool async)
7535+
{
7536+
await base.Cast_to_object_over_parameter_directly_in_lambda(async);
7537+
7538+
AssertSql(
7539+
"""
7540+
SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate]
7541+
FROM [Orders] AS [o]
7542+
""");
7543+
}
7544+
75347545
private void AssertSql(params string[] expected)
75357546
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);
75367547

0 commit comments

Comments
 (0)