Skip to content

Preserve implicit conversions during query precompilation - #39313

Merged
AndriySvyryd merged 8 commits into
mainfrom
copilot/fix-query-precompiler-issue
Nov 18, 2026
Merged

AndriySvyryd merged 8 commits into
mainfrom
copilot/fix-query-precompiler-issue

Conversation

Copilot AI commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Query precompilation drops implicit conversions when reconstructing conditional branches and binary operands. This causes valid C# projections with nullable results—and equality comparisons requiring user-defined conversions—to fail during expression-tree construction.

  • Translation

    • Apply conversions using Roslyn’s semantic ConvertedType before constructing conditional and binary nodes.
    • Preserve compiler-style reference equality and existing is/as handling.
  • Coverage

    • Cover nullable lifting in either branch, explicit-cast controls, numeric conversions, and custom-type equality/inequality.
    • Add a shared precompiled-query regression covering generation, generated-code compilation, and execution.

Nullable constructor arguments no longer require an explicit cast on the non-null branch:

new GenerationMetric(
    state,
    count,
    hasCompleted ? durations.Average() : null)

Copilot AI changed the title [WIP] Fix query precompiler failing to lift double branch in nullable conditional Preserve implicit conversions during query precompilation Oct 17, 2026
Copilot AI requested a review from AndriySvyryd October 17, 2026 03:14
Comment thread .agents/skills/query-pipeline/SKILL.md Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Agent harness evaluation deferred

This PR affects: query-pipeline. Automatic evaluation is deferred because this PR is currently marked as draft. Once it is ready for review, the usual author authorization rules apply. A contributor with write access can comment /eval or /eval component-name, or run the workflow manually for pull request #39313.

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.

🔵 Needs a closer look

Binary conversion handling affects multiple operators, and Roslyn and provider regression tests were not executed during this review.

No open issues 🎉

What changed in this PR

Fixes query precompilation failures by preserving implicit conversions when reconstructing expression trees.

Changes:

  • Applies semantic conversions to conditional branches and binary operands while preserving reference equality and is/as handling.
  • Adds conversion-focused unit tests and a shared precompiled-query regression with SQL Server assertions.
  • Documents the conversion requirement in query-pipeline guidance.
File Description
test/​EFCore.SqlServer.FunctionalTests/​Query/​AdHocPrecompiledQuerySqlServerTest.cs Adds SQL baseline for the regression.
test/​EFCore.Relational.Specification.Tests/​Query/​AdHocPrecompiledQueryRelationalTestBase.cs Adds shared generation, compilation, and execution coverage.
test/​EFCore.Design.Tests/​Query/​CSharpToLinqTranslatorTest.cs Tests nullable, numeric, and user-defined conversions.
src/​EFCore.Design/​Query/​Internal/​CSharpToLinqTranslator.cs Preserves semantic operand and branch conversions.
.agents/​skills/​query-pipeline/​SKILL.md Documents expression reconstruction requirements.

Review effort: Balanced

@AndriySvyryd
AndriySvyryd marked this pull request as ready for review October 17, 2026 04:35
@AndriySvyryd
AndriySvyryd requested a review from a team as a code owner October 17, 2026 04:35
@AndriySvyryd
AndriySvyryd requested review from cincuranet and a balanced review from Copilot October 17, 2026 04:35

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.

🟡 Changes recommended

Conversion reconstruction can select an explicit operator instead of the source’s implicit conversion, changing query results.

1 open issue

Review effort: Balanced

@github-code-quality

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

Copy link
Copy Markdown

Code coverage overview

Languages: C#

C# / code-coverage

main 6842690 copilot/fix-query-pr... 05818df +/-
76% 76% 0%
View coverage of the 10 most impacted files.
File main 6842690 copilot/fix-query-pr... 05818df +/-
src/EFCore.Sqli...ryRepository.cs 97% 86% -11%
src/EFCore/Quer...eFuncletizer.cs 87% 87% 0%
src/EFCore.Desi...nqTranslator.cs 84% 84% 0%
src/EFCore.Abst...erExtensions.cs 100% 100% 0%
src/EFCore.Cosm...nsExtensions.cs 82% 82% 0%
src/EFCore.Desi...seOperations.cs 98% 98% 0%
src/EFCore.Desi...eportHandler.cs 47% 47% 0%
src/Shared/NonC...yInitializer.cs 11% 12% +1%
src/EFCore.Rela...osticsLogger.cs 98% 99% +1%
src/EFCore.Rela...alConnection.cs 93% 94% +1%

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


Updated November 13, 2026 06:11 UTC

Copilot AI balanced review requested due to automatic review settings October 21, 2026 23:12

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.

🟡 Changes recommended

Operator lookup ambiguity and incorrect nullable-lifting detection still cause valid C# queries to fail during precompilation.

2 open issues
1 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 22, 2026 01:03

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.

🔵 Needs a closer look

Compiler-sensitive conversion and nullable-lifting behavior needs regression-suite confirmation against the pinned SDK before approval.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 30, 2026 23:46

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 were identified for the change restoring implicit conversions in query precompilation.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 13, 2026 05:43
@AndriySvyryd
AndriySvyryd enabled auto-merge (squash) November 13, 2026 05:45

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 recorded for the implicit-conversion precompilation changes.

No open issues 🎉

Review effort: Balanced

@AndriySvyryd
AndriySvyryd merged commit e9630d6 into main Nov 18, 2026
22 of 23 checks passed
@AndriySvyryd
AndriySvyryd deleted the copilot/fix-query-precompiler-issue branch November 18, 2026 10:52
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

4 participants