Repository navigation
feat(searchy): send filter values as parameters and sort on any type - #64
Merged
Merged
Conversation
Filter values were embedded in the expression tree as constants. EF Core then compiled, cached and sent a new SQL text for every distinct value, so a search screen typing different numbers filled the query cache and the database's statement statistics with one entry per value. Values are now captured the way closure variables are, so EF Core sends them as parameters: a query shape compiles once, whatever the values, and lists go as a single array parameter (= ANY (@p) on PostgreSQL). Also: - Values convert with the invariant culture, so "100.5" means the same on every server, and the conversion now covers Guid, enums by name or number, booleans written as 1/0, DateTimeOffset, DateOnly and TimeSpan. - Sorting accepts any property type (bool, long, enums, Guid, nullable numbers...) and dotted paths, not just seven types on top-level properties. - An unknown filter or sort field throws an SWException naming it, instead of a NullReferenceException. - Searchy's source is shared by both packages; each keeps only its text rule (string methods in the core package, escaped ILIKE in PgSql). Adds SW.EfCoreExtensions.PgSql.IntegrationTests (PostgreSQL 17 through Testcontainers) and a pull-request workflow running both test projects. 13 of its 17 cases fail against 10.0.2. Publishes as 10.1.x.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
AhmadRAbuhussein
approved these changes
Oct 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
Searchy embedded every filter value in the expression tree as a constant. EF Core then compiled, cached and sent a new SQL text per distinct value: a search screen where users type different numbers fills EF's query cache, and the database's statement statistics, with one entry per value, and every new value pays a full query compilation.
Measured with EF Core 10 / Npgsql 10 against PostgreSQL 17: 20 searches with 20 different values → 20 compilations with constants, 1 with captured values.
What changes
@pinstead of a literal. Lists become one array parameter (= ANY (@p)on PostgreSQL) whatever their length."100.5"means the same on every server. The conversion now also coversGuid(it used to throw), enums by name or number, booleans written as1/0,DateTimeOffset,DateOnlyandTimeSpan. A value ending inZstays UTC, as before.bool,long, enums,Guid, nullable numbers and dotted paths such asCustomer.Address.City. Previously: seven types, top-level properties only, anything else threw.SWExceptionnaming it, not aNullReferenceException.SW.EfCoreExtensions/Searchy/, linked into PgSql). Each package keeps only its text rule: string methods in core, escapedILIKEin PgSql.No public API changes. The SQL changes from literals to parameters, and lists from
IN (...)to= ANY (@p), hence 10.1.x (minor-version: '1').Tests
SW.EfCoreExtensions.PgSql.IntegrationTests: PostgreSQL 17 through Testcontainers, a small orders/customers domain, asserting on the SQL text and EF Core's compilation count. 17/17 pass; against 10.0.2, 13 of them fail.tests.ymlruns both projects on every pull request; the publish workflow still hasrun-tests: false.