Skip to content

Preserve implicit conversions during query precompilation - #39313

Open
AndriySvyryd with Copilot wants to merge 6 commits into
mainfrom
copilot/fix-query-precompiler-issue
Open

AndriySvyryd with Copilot wants to merge 6 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)

…xpressions

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
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 Outdated
@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.

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>

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

Comment thread src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs Outdated
@github-code-quality

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

Copy link
Copy Markdown

Code coverage overview

Languages: C#

C# / code-coverage

main 4317e84 copilot/fix-query-pr... 44a37a2 +/-
76% 76% 0%
View coverage of the 10 most impacted files.
File main 4317e84 copilot/fix-query-pr... 44a37a2 +/-
src/EFCore.Desi...nqTranslator.cs 84% 84% 0%
src/EFCore.Abst...erExtensions.cs 100% 100% 0%
src/EFCore.Anal...icSuppressor.cs 96% 96% 0%
src/EFCore.Desi...CSharpHelper.cs 96% 96% 0%
src/EFCore.Desi...seOperations.cs 91% 91% 0%
src/EFCore.Desi...xtOperations.cs 57% 57% 0%
src/EFCore.Desi...ySafetyRules.cs 94% 94% 0%
src/EFCore.Rela...osticsLogger.cs 98% 99% +1%
src/EFCore.Rela...CommandCache.cs 98% 100% +2%
src/Microsoft.D...nnectionPool.cs 97% 100% +3%

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


Updated October 22, 2026 01:33 UTC

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
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

Comment thread src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs Outdated
Comment thread src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 22, 2026 01:03
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query precompiler fails to lift a double branch in a target-typed nullable conditional

3 participants