Adding support for multiple and named query filters #35104
+423
−81
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've read the guidelines for contributing and seen the walkthrough
The code builds and tests pass locally (also verified by our automated build checks)
Tests for the changes have been added (for bug fixes / features)
Code follows the same patterns and style as existing code in this repo
Closes #8576
This PR adds support for defining multiple named global query filters on an entity.
It follows pattern used for keyed services in ASP.NET Core dependency injection.
It's backward compatible with the existing implementation where only single unnamed filter was possible.
Examples:
The example above shows the basic usage of the feature. As you can see we can use a value of any type as a filter key. In our example it was string and enum values. If the filter key is not defined as it is in
HasQueryFilter(x => !_ids.Contains(x.Id))
, string.Empty is used under the hood. It can be later used to disable that anonymous filter.This example shows how to ignore specific query filters by using their keys. To simplify the use we can use an overload allowing us to specify filters keys as params array. Sequential use of the method adds new keys to the ignored list. Note, that the string.Empty key disables the anonymous filter from the previous example.
If we want to ignore all filters at once we can do it be calling
IgnoreQueryFilters
overload with no parameters: