Skip to content

Translate ToString() on string expressions - #4047

Merged
roji merged 1 commit into
mainfrom
roji-triage-issue-4046
Oct 20, 2026
Merged

roji merged 1 commit into
mainfrom
roji-triage-issue-4046

Conversation

@roji

@roji roji commented Oct 20, 2026

Copy link
Copy Markdown
Member

Return string-mapped instances unchanged in NpgsqlObjectToStringTranslator, matching SQL Server and SQLite rather than adding a cast or coalescing nulls to an empty string.

Add focused regression coverage for string predicates, null propagation, and object-typed string grouping keys used in OrderBy and Where. Align with upstream coverage by adding SQL assertions for the inherited ToString_string_property_projection test in the GearsOfWar, TPC, and TPT suites.

Fixes #4046.

Related to dotnet/efcore#20839, implemented upstream in dotnet/efcore#29349.

Match SQL Server and SQLite by returning string-mapped instances unchanged. Add focused predicate and grouping coverage and SQL assertions for the upstream string projection test.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 839e4245-5519-4593-84c7-2dfb4c10b82a
Copilot AI balanced review requested due to automatic review settings October 20, 2026 10:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The localized change has targeted regression coverage and no identified blocking issues; tests were not executed.

No open issues 🎉

What changed in this PR

Fixes #4046 by translating ToString() on string-mapped expressions as the original SQL expression, preserving nulls without adding casts.

Changes:

  • Adds string passthrough handling to the object-to-string translator.
  • Covers predicates, null propagation, and object-typed grouping keys.
  • Adds inherited projection SQL assertions across three query suites.
File Description
test/​EFCore.PG.FunctionalTests/​Query/​Translations/​StringTranslationsNpgsqlTest.cs Adds focused translation regression tests.
test/​EFCore.PG.FunctionalTests/​Query/​Inheritance/​TPTGearsOfWarQueryNpgsqlTest.cs Asserts string projection SQL for TPT.
test/​EFCore.PG.FunctionalTests/​Query/​Inheritance/​TPCGearsOfWarQueryNpgsqlTest.cs Asserts string projection SQL for TPC.
test/​EFCore.PG.FunctionalTests/​Query/​GearsOfWarQueryNpgsqlTest.cs Asserts string projection SQL.
src/​EFCore.PG/​Query/​ExpressionTranslators/​Internal/​NpgsqlObjectToStringTranslator.cs Returns string-mapped expressions unchanged.

Review effort: Balanced

@roji
roji merged commit 5374dda into main Oct 20, 2026
16 checks passed
@roji
roji deleted the roji-triage-issue-4046 branch October 20, 2026 12:06
roji added a commit that referenced this pull request Oct 20, 2026
Backport #4047 (5374dda) with its regression coverage. Adapt test paths and the EF 10 element sorter nullable annotation.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b3737668-7ab2-46a4-9dcb-53e88f145a02
roji added a commit that referenced this pull request Oct 20, 2026
Backport #4047, adapting focused regressions to the existing Northwind functions suite. Retain inherited GearsOfWar, TPC and TPT projection SQL assertions.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 8445f728-0ea4-4167-ac34-f40a4d7e9657
roji added a commit that referenced this pull request Oct 20, 2026
Backport #4047 (5374dda), adapting focused regression tests to the EF Core 8 Northwind model.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8abbdb3d-122e-4300-b2dc-9c8482db2ec2
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.

ToString() on a string expression fails to translate (“Translation of method ‘object.ToString’ failed”)

2 participants