Skip to content

Fix funcletization of evaluatable lambda parameters#38291

Merged
roji merged 4 commits into
mainfrom
roji/triage-38287
May 19, 2026
Merged

Fix funcletization of evaluatable lambda parameters#38291
roji merged 4 commits into
mainfrom
roji/triage-38287

Conversation

@roji
Copy link
Copy Markdown
Member

@roji roji commented May 18, 2026

Fixes #38287.

Prevents ParameterExpressions that are made evaluatable for LINQ-to-Objects Enumerable.Select lambdas from being evaluated as independent roots, where they are unbound. The parameter remains evaluatable only as part of the larger lambda fragment via NotEvaluatableAsRootHandler.

Adds shared Northwind query coverage for SelectMany over an inline array projecting both the range variable and the outer entity, with SQL Server baseline and SQLite/Cosmos provider overrides.

Validation:

  • dotnet test .\test\EFCore.SqlServer.FunctionalTests\EFCore.SqlServer.FunctionalTests.csproj --filter "FullyQualifiedName~NorthwindSelectQuerySqlServerTest.SelectMany_over_inline_array_projecting_range_variable_and_outer" --no-restore
  • dotnet test .\test\EFCore.Sqlite.FunctionalTests\EFCore.Sqlite.FunctionalTests.csproj --filter "FullyQualifiedName~NorthwindSelectQuerySqliteTest.SelectMany_over_inline_array_projecting_range_variable_and_outer" --no-restore
  • dotnet test .\test\EFCore.Cosmos.FunctionalTests\EFCore.Cosmos.FunctionalTests.csproj --filter "FullyQualifiedName~NorthwindSelectQueryCosmosTest.SelectMany_over_inline_array_projecting_range_variable_and_outer" --no-restore
  • dotnet test .\test\EFCore.SqlServer.FunctionalTests\EFCore.SqlServer.FunctionalTests.csproj --filter "FullyQualifiedName~Microsoft.EntityFrameworkCore.Query" --no-restore -- xUnit.MaxParallelThreads=1

Prevent parameters made evaluatable for LINQ-to-Objects Select lambdas from being evaluated as independent roots, where they are unbound. Add shared Northwind query coverage with provider overrides.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 18, 2026 11:07
@roji roji requested a review from a team as a code owner May 18, 2026 11:07
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a funcletization edge case where ParameterExpressions (made evaluatable to allow LINQ-to-Objects Enumerable.Select lambda evaluation) could be treated as standalone evaluatable roots and evaluated while unbound, causing InvalidOperationException: unbound variable.

Changes:

  • Mark ParameterExpressions allowed for Enumerable.Select as not evaluatable as roots, preventing invalid standalone evaluation.
  • Add shared Northwind coverage for SelectMany over an inline array projecting both the range variable and the outer entity.
  • Add/adjust provider-specific expectations (SQL Server SQL baseline; SQLite/Cosmos translation failure behaviors).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs Prevents evaluatable lambda parameters from being evaluated as independent roots via NotEvaluatableAsRootHandler.
test/EFCore.Specification.Tests/Query/NorthwindSelectQueryTestBase.cs Adds shared repro coverage for SelectMany + inline array + projection of both range variable and outer entity.
test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSelectQuerySqlServerTest.cs Adds SQL Server baseline assertion for the new shared test.
test/EFCore.Sqlite.FunctionalTests/Query/NorthwindSelectQuerySqliteTest.cs Adds provider override asserting APPLY not supported for the new test.
test/EFCore.Cosmos.FunctionalTests/Query/NorthwindSelectQueryCosmosTest.cs Adds provider override asserting translation failure for the new test (client-eval limitation).

roji and others added 2 commits May 18, 2026 13:23
Keep ParameterExpression handling aligned with the other non-evaluatable-root cases, where evaluatable state is expected to provide a handler.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The shared Northwind regression test is relational-only behavior for providers which can translate APPLY; InMemory should assert the existing translation failure like the other unsupported providers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 18, 2026 12:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs
Use a descriptive local name for the ParameterExpression captured by the non-evaluatable-root handler.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@AndriySvyryd AndriySvyryd assigned roji and unassigned AndriySvyryd May 19, 2026
@roji roji merged commit 0cbee6e into main May 19, 2026
13 checks passed
@roji roji deleted the roji/triage-38287 branch May 19, 2026 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SelectMany with inline array values over Where crashes ExpressionTreeFuncletizer with InvalidOperationException

3 participants