Skip to content

Conversation

@cincuranet
Copy link
Contributor

Fixes #37653.

@cincuranet cincuranet force-pushed the fix-cond-coalesce branch 2 times, most recently from 613da26 to 6d45108 Compare February 10, 2026 07:10
@cincuranet cincuranet marked this pull request as ready for review February 10, 2026 07:41
@cincuranet cincuranet requested a review from a team as a code owner February 10, 2026 07:41
Copilot AI review requested due to automatic review settings February 10, 2026 07:41
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

Fixes EF Core query translation when a boolean (including nullable boolean) with a value converter is used as a searched CASE condition, ensuring the SQL compares against the converted “true” value (e.g. = 10) rather than treating the converted numeric directly as a predicate.

Changes:

  • Extend value-converter compensation to cover bool? and function expressions (e.g. COALESCE(...)) for relational providers.
  • Add Cosmos compensation for bool/bool? expressions with value converters in predicate contexts.
  • Add/extend tests across Specification, SQLite, SQL Server, and Cosmos to validate correct results and (where applicable) SQL generation.

Reviewed changes

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

Show a summary per file
File Description
src/EFCore.Relational/Query/Internal/RelationalValueConverterCompensatingExpressionVisitor.cs Compensates searched predicates for bool/bool? with converters, now including function expressions like COALESCE.
src/EFCore.Cosmos/Query/Internal/CosmosValueConverterCompensatingExpressionVisitor.cs Adds compensation for bool/bool? expressions with converters in Cosmos SQL expression tree.
test/EFCore.Specification.Tests/Query/AdHocMiscellaneousQueryTestBase.cs Adds repro test for conditional over COALESCE on a converted nullable bool.
test/EFCore.Sqlite.FunctionalTests/Query/AdHocMiscellaneousQuerySqliteTest.cs Provider-specific SQL assertion verifying COALESCE(...) = 10 in searched CASE.
test/EFCore.SqlServer.FunctionalTests/Query/AdHocMiscellaneousQuerySqlServerTest.cs Provider-specific SQL assertion verifying typed COALESCE(...) = CAST(10 AS smallint) in searched CASE.
test/EFCore.Cosmos.FunctionalTests/Query/AdHocMiscellaneousQueryCosmosTest.cs Adds Cosmos functional test to validate correct results for the same LINQ pattern.

Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM. There are various problems with this visitor, but that's out of scope here.

@roji roji merged commit b02d3e6 into dotnet:main Feb 11, 2026
10 checks passed
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.

Incorrect compensation for bool with value converter in CASE

2 participants