-
-
Notifications
You must be signed in to change notification settings - Fork 158
Filtering with "any" requires more than one entry in the set #1152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is by design. A set must contain at least two elements. A single element is a scalar value, for which other operators already exist. And an empty set for this operator makes no sense. |
@bkoelman Just stumbled on the same issue. Filter syntax section of documentation indicates this filter should work with 1 and more values, please update accordingly. But it would be much more convenient to support 1 value as well when list of filters depends on user input. |
I'd be interested to learn why you expect a set to have two or more elements @bkoelman - granted its a long time since I've done any set theory, but I cant remember anything limiting the number of items in a valid set (not to mention the empty set, which is an entirely valid set, with no elements...) |
I don't think that it does. It is defined as:
Where The design consideration was to avoid providing multiple ways to achieve the same thing. For a single term, |
Let me elaborate a bit (at the risk of contradicting what I said before). The "any" function was added as a shorter way of or-ing multiple equality checks, simply because it's a commonly used pattern. For example, What makes it problematic to choose between equals and any based on user input? |
It would be more end user friendly to not have to special case 1 element array for the filter construction. That it has performance implications when translated to SQL is leaking abstraction in my opinion and should be taken care of in the translation below the filter abstraction rather than make it end user responsibilty. That said, it's just a minor nuisance so I opted to not continue to nag about it.. but since more people are being affected perhaps it should be reconsidered. |
Thanks for the feedback @bkoelman - appreciate the consideration you have put into this.
The case I have is an integration API provided to client companies, who implement their own front ends - so we do not control the client code. As such our choices are to compell clients to code around this, or work around it ourselves with custom code or a fork, and I would much prefer to fix this in the official version, for everyone :) |
It turns out that EF Core translates single-element collections to
Thanks all for providing this feedback! |
If a single element is given it results in error message "The specified filter is invalid" and detail ", expected.".
The text was updated successfully, but these errors were encountered: