Skip to content

Conversation

@roji
Copy link
Member

@roji roji commented Dec 31, 2025

Fixes #37409

@roji roji marked this pull request as ready for review December 31, 2025 10:38
@roji roji requested a review from a team as a code owner December 31, 2025 10:38
Copilot AI review requested due to automatic review settings December 31, 2025 10:38
Copy link

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

This PR fixes issue #37409 where duplicate DbParameter instances in a SQL tree were having their names uniquified multiple times, leading to incorrect parameter references. The issue occurs when SQL tree fragments are duplicated during query translation (e.g., in GroupBy operations).

Key Changes

  • Added deduplication logic to track already-processed DbParameter instances using a dictionary keyed by DbParameter reference
  • Refactored ProcessDbParameter to return RawRelationalParameter instead of modifying the parameter in-place without returning a value
  • Added a test case demonstrating the GroupBy scenario that triggers SQL tree duplication

Reviewed changes

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

File Description
src/EFCore.Relational/Query/Internal/RelationalParameterProcessor.cs Added _processedDbParameters dictionary to cache processed DbParameters and prevent duplicate name uniquification; refactored ProcessDbParameter to return the created RawRelationalParameter
test/EFCore.Relational.Specification.Tests/Query/FromSqlQueryTestBase.cs Added test FromSql_GroupBy_non_reducing_Select to verify the fix handles duplicated SQL tree fragments with DbParameters
test/EFCore.SqlServer.FunctionalTests/Query/FromSqlQuerySqlServerTest.cs Added SQL baseline for the new test showing the same @city parameter correctly used twice in the generated SQL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant