Skip to content

Allow at least one constant instead of two in any() filter function #1234

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

Merged
merged 1 commit into from
Dec 21, 2022

Conversation

bkoelman
Copy link
Member

It turns out that EF Core 6 (tested with PostgreSQL and Sqlite) is smart enough to translate a single-element collection to a SQL = expression, instead of IN (...):

.Where((FilterableResource filterableResource) => #List<string>.Contains(filterableResource.SomeString))
.OrderBy((FilterableResource filterableResource) => filterableResource.Id)
.Take(Tuple.Create(10).Item1)

Multiple elements for #List<string> reference:

-- Executed DbCommand (2ms) [Parameters=[@__Create_Item1_0='10'], CommandType='Text', CommandTimeout='30']
SELECT f.*
FROM "FilterableResources" AS f
WHERE f."SomeString" IN ('four', 'three', 'one', 'two', 'five')
ORDER BY f."Id"
LIMIT @__Create_Item1_0

Single element:

-- Executed DbCommand (1ms) [Parameters=[@__Create_Item1_0='10'], CommandType='Text', CommandTimeout='30']
SELECT f.*
FROM "FilterableResources" AS f
WHERE f."SomeString" = 'yes'
ORDER BY f."Id"
LIMIT @__Create_Item1_0

Closes #1152.

QUALITY CHECKLIST

@bkoelman bkoelman force-pushed the allow-single-constant-in-any-function branch from a0c4007 to faaba0b Compare December 21, 2022 10:33
@codecov
Copy link

codecov bot commented Dec 21, 2022

Codecov Report

Merging #1234 (faaba0b) into master (84d01c3) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #1234   +/-   ##
=======================================
  Coverage   92.62%   92.63%           
=======================================
  Files         243      243           
  Lines        7799     7794    -5     
=======================================
- Hits         7224     7220    -4     
+ Misses        575      574    -1     
Impacted Files Coverage Δ
...otNetCore/Queries/Internal/Parsing/FilterParser.cs 98.35% <ø> (-0.03%) ⬇️
...ApiDotNetCore/Queries/Expressions/AnyExpression.cs 73.33% <100.00%> (+1.45%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@bkoelman bkoelman marked this pull request as ready for review December 21, 2022 11:59
@bkoelman bkoelman requested a review from maurei December 21, 2022 12:00
@maurei maurei merged commit 85bdd01 into master Dec 21, 2022
@maurei maurei deleted the allow-single-constant-in-any-function branch December 21, 2022 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Filtering with "any" requires more than one entry in the set
2 participants