Skip to content

Comments

Fix: Named query filters cannot override convention-set filters#37710

Merged
roji merged 3 commits intomainfrom
copilot/fix-named-query-filters-override
Feb 18, 2026
Merged

Fix: Named query filters cannot override convention-set filters#37710
roji merged 3 commits intomainfrom
copilot/fix-named-query-filters-override

Conversation

Copy link
Contributor

Copilot AI commented Feb 14, 2026

Fix Named Query Filter Override from Convention

  • Understand the issue: Named query filters set by conventions cannot be overridden explicitly
  • Identify root cause: EntityTypeBuilder.HasQueryFilter(string, LambdaExpression) doesn't set ConfigurationSource
  • Fix EntityTypeBuilder.HasQueryFilter to pass ConfigurationSource.Explicit
  • Create test to verify conventions can be overridden by explicit configuration
  • Run existing tests to ensure no regressions
  • Run broader test suite to verify no regressions (611 tests passed)
  • Verify the fix with code review and security scan (both passed)
  • Address review feedback: Remove QueryFilter constructors without ConfigurationSource
  • Make ConfigurationSource property non-nullable
Original prompt

This section details on the original issue you should resolve

<issue_title>Cannot Override Named Query Filters Set via Convention</issue_title>
<issue_description>### Bug description

We're in the process of upgrading to EF 10. We have a Convention Set that automatically adds query filters to certain types. We are switching this over to named query filters and have noticed that once the convention sets the filter (with Configuration Source == Convention) that a user cannot override the filter with the same name explicitly

I think this is because of the difference in the code for adding global and named filters:

This code sets the configuration source explicitly:

public virtual EntityTypeBuilder HasQueryFilter(LambdaExpression? filter)
{
Builder.HasQueryFilter(filter, ConfigurationSource.Explicit);
return this;
}

While this code only calls the QueryFilter constructor and never sets a configuration source.

public virtual EntityTypeBuilder HasQueryFilter(string filterKey, LambdaExpression? filter)
{
Builder.HasQueryFilter(new QueryFilter(filterKey, filter));
return this;
}

Later on when performing CanSetQueryFilter, the configuration source on the new (explicit) filter is null and thus the old one wins.

Is this intended or is it a bug?

Your code

In a convention:


IConventionEntityTypeBuilder builder = ...;
builder.HasQueryFilter("SomeName", Expression.Lambda(...));


In a user provided configuration:


EntityTypeBuilder<SomeType> builder = ...;
builder.HasQueryFilter("SomeName", s => ...);  // <--- doesn't override


I apologize for the snippets here; it's a bit difficult to provide a full sample with a convention set etc. and I'm not at my desk currently. But if needed I can try and put together the full thing. I was hoping it was just "obviously" intended or a bug

Stack traces


Verbose output


EF Core version

10.0.3

Database provider

No response

Target framework

.NET 10

Operating system

No response

IDE

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Pass ConfigurationSource.Explicit when creating QueryFilter in EntityTypeBuilder.HasQueryFilter(string, LambdaExpression) so that explicit configurations can override convention-set named query filters.

Co-authored-by: roji <1862641+roji@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix named query filters not overriding convention filters Fix: Named query filters cannot override convention-set filters Feb 14, 2026
Copilot AI requested a review from roji February 14, 2026 17:23
Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @AndriySvyryd for ultimate authority

@roji roji assigned AndriySvyryd and unassigned roji Feb 14, 2026
@roji roji marked this pull request as ready for review February 14, 2026 18:07
@roji roji requested a review from a team as a code owner February 14, 2026 18:07
Copilot AI review requested due to automatic review settings February 14, 2026 18:07
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where named query filters set by conventions could not be overridden by explicit user configuration. The issue was that the public API method EntityTypeBuilder.HasQueryFilter(string, LambdaExpression) was not passing a ConfigurationSource when constructing the QueryFilter object, preventing proper configuration precedence checks.

Changes:

  • Fix EntityTypeBuilder.HasQueryFilter to pass ConfigurationSource.Explicit when creating named query filters, matching the pattern already used for unnamed filters
  • Add test verifying explicit configuration can override convention-set named query filters

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/EFCore/Metadata/Builders/EntityTypeBuilder.cs Add ConfigurationSource.Explicit parameter to QueryFilter constructor for named filters
test/EFCore.Tests/Metadata/Internal/InternalEntityTypeBuilderTest.cs Add test verifying convention-set named filters can be overridden by explicit configuration

@roji roji enabled auto-merge (squash) February 14, 2026 22:56
@roji
Copy link
Member

roji commented Feb 17, 2026

@AndriySvyryd possibly take a look at #37708 (comment) while reviewing? Or we can treat that as a separate thing if better.

Remove QueryFilter constructors that don't accept ConfigurationSource and make the ConfigurationSource property non-nullable. This ensures all QueryFilter instances have a valid configuration source for proper override behavior.

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
auto-merge was automatically disabled February 17, 2026 19:24

Head branch was pushed to by a user without write access

Copilot AI requested a review from AndriySvyryd February 17, 2026 19:26
@roji roji merged commit 35089f2 into main Feb 18, 2026
11 checks passed
@roji roji deleted the copilot/fix-named-query-filters-override branch February 18, 2026 17:15
Copilot AI added a commit that referenced this pull request Feb 18, 2026
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI added a commit that referenced this pull request Feb 20, 2026
Co-authored-by: roji <1862641+roji@users.noreply.github.com>
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.

Cannot override named query filters set via convention

3 participants