Skip to content

Support unqualified class constants in query precompilation - #39298

Merged
AndriySvyryd merged 2 commits into
mainfrom
copilot/fix-unknown-identifier-checkpointid
Nov 4, 2026
Merged

AndriySvyryd merged 2 commits into
mainfrom
copilot/fix-unknown-identifier-checkpointid

Conversation

Copilot AI commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Query precompilation rejects unqualified class constants in predicates as unknown identifiers, even though equivalent literals and captured locals work.

  • Translation: Convert constant-field symbols to typed constant expressions, preserving enum values and typed nulls.
  • Regression coverage: Add translator cases and a shared async query regression with a private class constant and cancellation-token parameter, plus SQLite and SQL Server SQL baselines.

This enables predicates such as:

private const int CheckpointId = 1;

// Inside a query method:
return context.Checkpoints.SingleOrDefaultAsync(
    x => x.Id == CheckpointId, cancellationToken);

Copilot AI changed the title [WIP] Fix query precompiler rejecting class constant in predicate Support unqualified class constants in query precompilation Oct 16, 2026
Copilot AI requested a review from AndriySvyryd October 16, 2026 22:25
@AndriySvyryd
AndriySvyryd requested a lite review from Copilot October 17, 2026 04:08

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

Constant translation must use Roslyn’s contextual converted type to support implicit conversions correctly.

No open issues 🎉

What changed in this PR

Adds support for unqualified class constants in query precompilation, including enums and typed nulls.

Changes:

  • Translate constant fields into typed expression constants.
  • Add translator regression tests.
  • Add relational, SQLite, and SQL Server coverage with SQL baselines.
File Summary
test/​EFCore.SqlServer.FunctionalTests/​Query/​PrecompiledQuerySqlServerTest.cs Adds SQL Server query coverage and baseline.
test/​EFCore.Sqlite.FunctionalTests/​Query/​PrecompiledQuerySqliteTest.cs Adds SQLite query coverage and baseline.
test/​EFCore.Relational.Specification.Tests/​Query/​PrecompiledQueryRelationalTestBase.cs Adds shared precompilation regression coverage.
test/​EFCore.Design.Tests/​Query/​CSharpToLinqTranslatorTest.cs Tests primitive, enum, and null constants.
src/​EFCore.Design/​Query/​Internal/​CSharpToLinqTranslator.cs Handles constant field symbols.

Review effort: Lite

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

Copy link
Copy Markdown

Code coverage overview

Languages: C#

C# / code-coverage

main 2e88827 copilot/fix-unknown-... 67531a9 +/-
76% 76% 0%
View coverage of the 10 most impacted files.
File main 2e88827 copilot/fix-unknown-... 67531a9 +/-
src/EFCore.Sqli...ryRepository.cs 97% 91% -6%
src/EFCore.Rela...CommandBatch.cs 89% 87% -2%
src/EFCore.Rela...CommandCache.cs 100% 98% -2%
src/EFCore.Rela...erExtensions.cs 96% 96% 0%
src/EFCore.Desi...nqTranslator.cs 83% 83% 0%
src/EFCore.Cosm...erExtensions.cs 100% 100% 0%
src/EFCore.Cosm...erExtensions.cs 46% 46% 0%
src/EFCore.Cosm...peExtensions.cs 73% 73% 0%
src/EFCore.Cosm...StreamHelper.cs 87% 87% 0%
src/Shared/NonC...yInitializer.cs 11% 12% +1%

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

@AndriySvyryd
AndriySvyryd enabled auto-merge (squash) October 31, 2026 00:27
@AndriySvyryd
AndriySvyryd merged commit 28dc36c into main Nov 4, 2026
29 checks passed
@AndriySvyryd
AndriySvyryd deleted the copilot/fix-unknown-identifier-checkpointid branch November 4, 2026 13:17
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 5, 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.

Query precompiler rejects class constant as unknown identifier in predicate

4 participants