Correct naming for for switch/case pattern-matched captured variables#37474
Correct naming for for switch/case pattern-matched captured variables#37474roji merged 1 commit intodotnet:mainfrom
Conversation
f885524 to
f266530
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #37465 by improving how EF Core names query parameters derived from captured variables in switch/case pattern matching expressions. The fix ensures that user-provided variable names are correctly extracted from compiler-generated field names containing angle brackets.
- Refactored parameter name sanitization logic to extract user variable names from compiler-generated angle bracket notation
- Added a new helper method
SanitizeCompilerGeneratedNamethat intelligently handles compiler-generated names - Added test coverage for switch/case pattern matching scenarios
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs | Refactored parameter naming logic: moved angle bracket handling to a new SanitizeCompilerGeneratedName method that extracts user variable names, and added validation to ensure parameter names start with a letter or underscore |
| test/EFCore.Specification.Tests/Query/NorthwindMiscellaneousQueryTestBase.cs | Added test case Captured_variable_from_switch_case_pattern_matching to verify correct parameter naming for variables captured from switch/case pattern matching |
| test/EFCore.SqlServer.FunctionalTests/Query/NorthwindMiscellaneousQuerySqlServerTest.cs | Added SQL Server test baseline showing the expected SQL output with @customerId parameter |
| test/EFCore.Cosmos.FunctionalTests/Query/NorthwindMiscellaneousQueryCosmosTest.cs | Added Cosmos DB test baseline showing the expected query output |
f266530 to
ebdb51a
Compare
|
@roji Thanks for the prompt fix. Do you know when the next release (that contains this fix) is scheduled? |
|
@Stephek see #37465 (comment). Since this affects a very narrow scenario and can be easily worked around (via an additional local variable), we likely won't be patching 10.0 with the fix (so 11.0 would be the first version with the fix). But if other users run into it, this may change. |
Fixes #37465