Skip to content

[release/11.0] Allow EF.Parameter and EF.Constant on context properties in query filters - #39091

Open
AndriySvyryd with Copilot wants to merge 5 commits into
release/11.0from
copilot/fix-non-compiled-query-filters
Open

AndriySvyryd with Copilot wants to merge 5 commits into
release/11.0from
copilot/fix-non-compiled-query-filters

Conversation

Copilot AI commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #39081

Description
A validation was added for compiled queries and global query filters to detect unsupported constants. That incorrectly rejected EF.Constant and EF.Parameter when their argument is a property on the current DbContext. The fix permits only operands that have been transformed into a context accessor and preserves rejection for literal and other non-context operands.

Customer impact
Applications using tenant or similar context state in a global query filter cannot execute affected non-compiled queries on EF Core 11 RC1.

modelBuilder.Entity<Blog>()
    .HasQueryFilter(blog => blog.TenantId == EF.Parameter(TenantId));

The query throws instead of applying the tenant filter. There is no practical workaround other than removing the explicit EF.Parameter or EF.Constant call.

How found
User reported on EF Core 11.0.0-rc1 in #39081. One customer report and one issue reaction indicate affected usage.

Regression
Yes, from EF 10.x. Introduced by #38155.

Testing
Tests added.

Risk
Low. The change is to revert to previous behavior in select cases.

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix regression for query filters in non-compiled queries Allow EF.Parameter and EF.Constant on context properties in query filters Sep 25, 2026
Copilot AI requested a review from AndriySvyryd September 25, 2026 00:05
@AndriySvyryd
AndriySvyryd requested a balanced review from Copilot September 25, 2026 00:22

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.

Copilot review overview

🟡 Changes recommended

The relaxed guards allow non-context operands that later cause InvalidCastException during normalization.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

Fixes query-filter funcletization for EF.Constant and EF.Parameter over context properties.

Changes:

  • Relaxes funcletizer guards during context-accessor generation.
  • Adds result and SQL regression coverage.
File Description
ExpressionTreeFuncletizer.cs Allows forcing methods in query-filter processing.
AdHocQueryFiltersQueryTestBase.cs Adds provider-agnostic regression tests.
AdHocQueryFiltersQuerySqlServerTest.cs Verifies constantized and parameterized SQL.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs
- Support EF.Constant and EF.Parameter on context properties\n- Preserve rejection for non-context operands\n\nFixes #39081\n\nCo-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@AndriySvyryd AndriySvyryd changed the title Allow EF.Parameter and EF.Constant on context properties in query filters [release/11.0] Allow EF.Parameter and EF.Constant on context properties in query filters Sep 25, 2026
@AndriySvyryd
AndriySvyryd requested a balanced review from Copilot September 25, 2026 01:25

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.

Copilot review overview

🟡 Changes recommended

Two new inherited tests lack required SQL Server overrides, causing Check_all_tests_overridden to fail.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (1)

Comment thread test/EFCore.Specification.Tests/Query/AdHocQueryFiltersQueryTestBase.cs Outdated
AndriySvyryd and others added 2 commits September 24, 2026 19:01
Fixes #39081

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Fixes #39081

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@AndriySvyryd
AndriySvyryd marked this pull request as ready for review September 25, 2026 04:47
@AndriySvyryd
AndriySvyryd requested a review from a team as a code owner September 25, 2026 04:47
Copilot AI review requested due to automatic review settings September 25, 2026 04:47

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.

Copilot review overview

🔵 Needs a closer look

The shared handler also changes undocumented and untested EF.MultipleParameters behavior.

Review effort: Balanced
Findings: None

Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Restrict relaxed guard to EF.Constant/EF.Parameter or add coverage

src/​EFCore/​Query/​Internal/​ExpressionTreeFuncletizer.cs:1189

HandleParameter is also used by EF.MultipleParameters (lines 969–973), so this relaxed guard enables context-backed MultipleParameters in query filters too. That behavior is outside the PR’s stated EF.Constant/EF.Parameter scope and has no acceptance or rejection coverage. Either retain the old rejection for MultipleParameters, or explicitly include it in scope and add equivalent context-property and literal tests.

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.

EF11 Regression: EF.Parameter/EF.Constant on a context property in a query filter now throws (non-compiled queries)

3 participants