Description
Is there a way to specify or override how QueryKit translates case-insensitive operators (e.g., @=*)? Specifically, I would like to configure the provider to use UPPER(value) instead of the default LOWER(value) during the expression building process.
Context & Environment
- .NET Version: 10
- Database Provider: Npgsql (PostgreSQL)
Use Case
In my domain model, I normalize certain fields like Email to uppercase at the application level using an EF Core Value Converter. This ensures data consistency and allows me to take advantage of uppercase B-tree indexes in PostgreSQL:
builder.Property(p => p.Email)
.HasConversion(
v => v.ToUpperInvariant(),
v => v);
When I perform a case-insensitive search using the QueryKit operator @=*, the resulting SQL is translated by EF Core as:
SELECT * FROM "Users" AS u
WHERE lower(u."Email") LIKE '%ALEX%'
The Problem
- Functional Mismatch: Because the data is stored as
ALEX@EXAMPLE.COM, the lower() function transforms it to alex@example.com. If the search term is provided in uppercase, the query returns no results.
- Index Usage: Using
LOWER() prevents PostgreSQL from using a standard index defined on the uppercase values. If QueryKit could be configured to produce an expression that EF translates to UPPER(), the SQL would be:
WHERE upper(u."Email") LIKE '%ALEX%'
This would correctly match my stored data and allow the database engine to utilize existing indexes effectively.
Questions
- Does QueryKit currently provide a configuration setting (perhaps in
QueryKitConfiguration) to choose between ToLower and ToUpper for case-insensitive operations?
- If not, would you be open to a PR for this feature?
- Could you point me toward the specific logic in the codebase where the case-insensitive expression is built so I can look into implementing a toggle?
Description
Is there a way to specify or override how QueryKit translates case-insensitive operators (e.g.,
@=*)? Specifically, I would like to configure the provider to useUPPER(value)instead of the defaultLOWER(value)during the expression building process.Context & Environment
Use Case
In my domain model, I normalize certain fields like
Emailto uppercase at the application level using an EF Core Value Converter. This ensures data consistency and allows me to take advantage of uppercase B-tree indexes in PostgreSQL:When I perform a case-insensitive search using the QueryKit operator
@=*, the resulting SQL is translated by EF Core as:The Problem
ALEX@EXAMPLE.COM, thelower()function transforms it toalex@example.com. If the search term is provided in uppercase, the query returns no results.LOWER()prevents PostgreSQL from using a standard index defined on the uppercase values. If QueryKit could be configured to produce an expression that EF translates toUPPER(), the SQL would be:This would correctly match my stored data and allow the database engine to utilize existing indexes effectively.
Questions
QueryKitConfiguration) to choose betweenToLowerandToUpperfor case-insensitive operations?