Fix funcletization of evaluatable lambda parameters#38291
Merged
Conversation
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>
There was a problem hiding this comment.
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 forEnumerable.Selectas not evaluatable as roots, preventing invalid standalone evaluation. - Add shared Northwind coverage for
SelectManyover 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). |
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>
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
approved these changes
May 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #38287.
Prevents
ParameterExpressions that are made evaluatable for LINQ-to-ObjectsEnumerable.Selectlambdas from being evaluated as independent roots, where they are unbound. The parameter remains evaluatable only as part of the larger lambda fragment viaNotEvaluatableAsRootHandler.Adds shared Northwind query coverage for
SelectManyover 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-restoredotnet test .\test\EFCore.Sqlite.FunctionalTests\EFCore.Sqlite.FunctionalTests.csproj --filter "FullyQualifiedName~NorthwindSelectQuerySqliteTest.SelectMany_over_inline_array_projecting_range_variable_and_outer" --no-restoredotnet test .\test\EFCore.Cosmos.FunctionalTests\EFCore.Cosmos.FunctionalTests.csproj --filter "FullyQualifiedName~NorthwindSelectQueryCosmosTest.SelectMany_over_inline_array_projecting_range_variable_and_outer" --no-restoredotnet test .\test\EFCore.SqlServer.FunctionalTests\EFCore.SqlServer.FunctionalTests.csproj --filter "FullyQualifiedName~Microsoft.EntityFrameworkCore.Query" --no-restore -- xUnit.MaxParallelThreads=1