Skip to content

Fix query precompilation for captured object properties - #39305

Merged
AndriySvyryd merged 5 commits into
mainfrom
copilot/fix-nre-query-precompiler
Nov 5, 2026
Merged

AndriySvyryd merged 5 commits into
mainfrom
copilot/fix-nre-query-precompiler

Conversation

Copilot AI commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Query precompilation dereferences null design-time placeholders when predicates capture properties of reference objects, throwing a parameter-evaluation exception even when the runtime object is non-null.

  • Parameter evaluation: Preserve member-chain parameter names without dereferencing null placeholders during precompilation and path calculation. Leave runtime and forced-constant evaluation unchanged.
  • Regression coverage: Cover initialized locals, entities returned by earlier queries, and foreach captures, including sync/async execution and SQL Server baselines. Verify genuinely null objects still throw at runtime before issuing SQL.
var item = new SyncItem { ModelProviderMappingId = 7 };
return db.Mappings.FirstOrDefaultAsync(
    m => m.Id == item.ModelProviderMappingId);

This shape can be precompiled without first copying the property into a scalar local.

Copilot AI changed the title [WIP] Fix parameter-evaluation NRE for captured object properties Fix query precompilation for captured object properties Oct 17, 2026
Copilot AI requested a review from AndriySvyryd October 17, 2026 01:36
Comment thread .agents/skills/query-pipeline/SKILL.md Resolved

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 narrowly scoped guard has focused regression coverage, with no identified blocking defects.

No open issues 🎉

What changed in this PR

Fixes query precompilation for captured object properties and guarded nullable values without changing runtime or forced-constant evaluation.

Changes:

  • Preserves parameter names without dereferencing null design-time placeholders.
  • Adds regression tests and SQL Server baselines for captured values and runtime null failures.
  • Documents the precompiled-query test helper’s validation scope.
File Description
test/​EFCore.SqlServer.FunctionalTests/​Query/​PrecompiledQuerySqlServerTest.cs Adds SQL baselines and verifies no SQL on runtime null failure.
test/​EFCore.Relational.Specification.Tests/​Query/​PrecompiledQueryRelationalTestBase.cs Adds shared captured-object and nullable-value regression tests.
src/​EFCore/​Query/​Internal/​ExpressionTreeFuncletizer.cs Skips null-placeholder member evaluation during precompilation.
.agents/​skills/​query-pipeline/​SKILL.md Documents generation, compilation, and execution validation.

Review effort: Balanced

Copilot AI requested a review from AndriySvyryd October 17, 2026 04:28
@AndriySvyryd
AndriySvyryd marked this pull request as ready for review October 17, 2026 04:36
@AndriySvyryd
AndriySvyryd requested review from a team and wtgodbe as code owners October 17, 2026 04:36
Copilot AI balanced review requested due to automatic review settings October 17, 2026 04:36
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Agent evaluation: query-pipeline

Status: error for a6937d8a46162419dcc200b60cdcd287c0da7f7d
Treatment quality threshold: ✅ passed
Required skill activation query-pipeline: ✅ passed

An error occurred while generating the evaluation report.

Download Vally reports · View workflow run

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 narrowly scoped guard preserves runtime evaluation and includes focused regression coverage, with no unresolved findings.

No open issues 🎉

Review effort: Balanced

@github-code-quality

Copy link
Copy Markdown

Code coverage overview

Languages: C#

C# / code-coverage

main 2e88827 copilot/fix-nre-quer... a6937d8 +/-
76% 76% 0%
View coverage of the 10 most impacted files.
File main 2e88827 copilot/fix-nre-quer... a6937d8 +/-
src/EFCore.Rela...CommandCache.cs 100% 98% -2%
src/EFCore.Rela...erExtensions.cs 96% 96% 0%
src/EFCore/Quer...eFuncletizer.cs 86% 86% 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/EFCore.Cosm...erExtensions.cs 87% 87% 0%
src/EFCore.Cosm...delValidator.cs 98% 98% 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:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

4 participants