Skip to content

Preserve nonnullable coalesce results in precompiled queries - #39314

Merged
AndriySvyryd merged 4 commits into
mainfrom
copilot/fix-precompiled-query-nullable
Nov 5, 2026
Merged

AndriySvyryd merged 4 commits into
mainfrom
copilot/fix-precompiled-query-nullable

Conversation

Copilot AI commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Precompiled-query generation reconstructs long? ?? long as long?, causing anonymous projections expecting long to fail with ArgumentException.

  • Translation: Handle ?? before nullable operand lifting, allowing Expression.Coalesce to infer the correct result type. Other binary operators remain unchanged.
  • Regression coverage: Add nullable/nonnullable fallback cases and anonymous-projection precompilation coverage for SQLite and SQL Server, including null and non-null values.
// Preserves SizeBytes as long without an outer cast.
.Select(media => new { SizeBytes = media.SizeBytes ?? 0L })

Copilot AI changed the title [WIP] Fix nullable-long coalesce in precompiled queries Preserve nonnullable coalesce results in precompiled queries Oct 17, 2026
Copilot AI requested a review from AndriySvyryd October 17, 2026 04:09
@AndriySvyryd
AndriySvyryd requested a lite review from Copilot October 17, 2026 04:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The reviewed changes are covered by focused translator and database regression tests.

No open issues 🎉

What changed in this PR

Fixes precompiled-query reconstruction of nullable coalesce expressions so nonnullable fallback results retain the correct CLR type.

Changes:

  • Handle coalesce expressions before nullable operand lifting.
  • Add translator regression tests.
  • Add SQLite and SQL Server end-to-end coverage.
File Description
test/​EFCore.SqlServer.FunctionalTests/​Query/​AdHocPrecompiledQuerySqlServerTest.cs Verifies SQL Server output.
test/​EFCore.Sqlite.FunctionalTests/​Query/​AdHocPrecompiledQuerySqliteTest.cs Verifies SQLite output.
test/​EFCore.Relational.Specification.Tests/​Query/​AdHocPrecompiledQueryRelationalTestBase.cs Adds shared end-to-end coverage.
test/​EFCore.Design.Tests/​Query/​CSharpToLinqTranslatorTest.cs Adds translator regression tests.
src/​EFCore.Design/​Query/​Internal/​CSharpToLinqTranslator.cs Preserves coalesce result types.

Review effort: Lite

@AndriySvyryd
AndriySvyryd marked this pull request as ready for review October 17, 2026 04:36
@AndriySvyryd
AndriySvyryd requested a review from a team as a code owner October 17, 2026 04:36
@github-code-quality

github-code-quality Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: C#

C# / code-coverage

main 8ece311 copilot/fix-precompi... e66d436 +/-
76% 76% 0%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 31, 2026 01:00 UTC

Copilot AI lite review requested due to automatic review settings October 31, 2026 00:29
@AndriySvyryd
AndriySvyryd enabled auto-merge (squash) October 31, 2026 00:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the focused translator fix and its accompanying regression coverage.

No open issues 🎉

Review effort: Lite

@AndriySvyryd
AndriySvyryd merged commit 846d13f into main Nov 5, 2026
22 of 24 checks passed
@AndriySvyryd
AndriySvyryd deleted the copilot/fix-precompiled-query-nullable branch November 5, 2026 09:57
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 6, 2026
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.

Precompiled queries reconstruct nullable-long coalesce with nullable result in anonymous projection

4 participants