Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct VisitUnary operand evaluation in funcletizer #35172

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1556,14 +1556,11 @@ UnaryExpression EvaluateOperand(UnaryExpression unary, Expression operand, State
operand = ProcessEvaluatableRoot(operand, ref operandState);
}

if (_state.ContainsEvaluatable)
{
_state = _calculatingPath
? State.CreateContainsEvaluatable(
typeof(UnaryExpression),
[_state.Path! with { PathFromParent = static e => Property(e, nameof(UnaryExpression.Operand)) }])
: State.NoEvaluatability;
}
_state = operandState.ContainsEvaluatable && _calculatingPath
? State.CreateContainsEvaluatable(
typeof(UnaryExpression),
[_state.Path! with { PathFromParent = static e => Property(e, nameof(UnaryExpression.Operand)) }])
: State.NoEvaluatability;

return unary.Update(operand);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5325,6 +5325,17 @@ public override async Task Column_access_inside_subquery_predicate(bool async)
AssertSql();
}

public override async Task Cast_to_object_over_parameter_directly_in_lambda(bool async)
{
// Sync always throws before getting to exception being tested.
if (async)
{
// Cosmos doesn't support ORDER BY over parameter/constant:
// Unsupported ORDER BY clause. ORDER BY item expression could not be mapped to a document path.
await Assert.ThrowsAsync<CosmosException>(() => base.Cast_to_object_over_parameter_directly_in_lambda(async: true));
}
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5897,4 +5897,15 @@ public virtual Task Column_access_inside_subquery_predicate(bool async)
=> AssertQuery(
async,
ss => ss.Set<Customer>().Where(c => ss.Set<Order>().Where(o => c.CustomerID == "ALFKI").Any()));

[ConditionalTheory] // #35152
[MemberData(nameof(IsAsyncData))]
public virtual Task Cast_to_object_over_parameter_directly_in_lambda(bool async)
{
var i = 8;

return AssertQuery(
async,
ss => ss.Set<Order>().OrderBy(o => (object)i).Select(o => o));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7531,6 +7531,17 @@ FROM [Orders] AS [o]
""");
}

public override async Task Cast_to_object_over_parameter_directly_in_lambda(bool async)
{
await base.Cast_to_object_over_parameter_directly_in_lambda(async);

AssertSql(
"""
SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate]
FROM [Orders] AS [o]
""");
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down