[release/10.0] Fix duplicate DbParameter naming uniquification#37541
Merged
roji merged 1 commit intodotnet:release/10.0from Feb 2, 2026
Merged
[release/10.0] Fix duplicate DbParameter naming uniquification#37541roji merged 1 commit intodotnet:release/10.0from
roji merged 1 commit intodotnet:release/10.0from
Conversation
There was a problem hiding this comment.
Pull request overview
This PR backports a fix for issue #37409, which addresses a regression in EF Core 10.0 where DbParameter instances get their names uniquified multiple times when SQL tree fragments are duplicated (e.g., in GroupBy translation). This causes invalid SQL generation where parameter names in subqueries don't match the renamed parameters.
Changes:
- Added caching mechanism to prevent duplicate processing of the same
DbParameterinstance - Implemented quirk switch for backward compatibility
- Added test coverage for the GroupBy scenario that triggers the issue
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/EFCore.Relational/Query/Internal/RelationalParameterProcessor.cs |
Core fix: Added _processedDbParameters dictionary to cache processed DbParameters and prevent duplicate uniquification |
test/EFCore.Relational.Specification.Tests/Query/FromSqlQueryTestBase.cs |
Added test case FromSql_GroupBy_non_reducing_Select that verifies the fix for the reported issue |
test/EFCore.SqlServer.FunctionalTests/Query/FromSqlQuerySqlServerTest.cs |
Added SQL Server-specific test baseline verifying correct SQL generation with single parameter reference |
artl93
approved these changes
Jan 20, 2026
Member
artl93
left a comment
There was a problem hiding this comment.
Regression from 9.0.x; multiple customers reported; straightforward repro; approved
AndriySvyryd
approved these changes
Jan 30, 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.
Backports #37430
Fixes #37409
Description
When using
Database.SqlQueryRaw<T>()orFromSqlRaw()withDbParameterinstances followed byGroupByand aSelectprojection, EF Core 10.x generates invalid SQL where the parameter is renamed at the outer query level but the inner subqueries still reference the original parameter name. This also affects simpler scenarios where the same DbParameter is referenced multiple times in a FromSql query.The issue occurs because when EF Core duplicates SQL tree fragments (e.g., in GroupBy translation), the same DbParameter instance gets referenced from multiple FromSqlExpressions, and its name gets uniquified multiple times, causing the parameter name to be modified repeatedly.
In addition, simpler scenarios have been flagged that make this more suitable for patching.
Customer impact
Applications using
SqlQueryRaworFromSqlRawwith DbParameter instances in combination with GroupBy or when the same DbParameter is referenced multiple times will encounter runtime failures with errors like "column does not exist" or "parameter not found".Workarounds exist but are enough of a pain (as well as undiscoverable) so as to IMHO justify this for patching.
How found
Customer reported via GitHub issue #37409. Multiple customers have been affected based on issue comments and related reports (npgsql/efcore.pg#3703).
Regression
Yes, this is a regression introduced in EF Core 10.0 by the parameter handling changes in PR #35200. The same code works correctly in EF Core 9.0.10.
Testing
Added.
Risk
Low. The fix is minimal and targeted. Quirk implemented.