In SQL Server, it is relatively straight forward to create a case-insensitive, accent-insensitive, LIKE
query using EF Core 5 and PredicateBuilder.
For example:
- The user is is trying to find a customer in the database using a standard North American keyboard (i.e. accents are kind of a pain to type).
- Searching for
helene
should matchMme. Hélène Laurendeau
. It is important we can match a substring and not just a prefix or suffix.
Assuming we have an entity Customer
with property Name
, the following snippet will work as expected:
var predicate = PredicateBuilder
.New<Customer>(c => EF.Functions.Collate(c.Name,
"Latin1_general_CI_AI")
.Contains("helen"));
var customers = context.Customers.AsExpandable().Where(predicate);
How we can we perform the same query in PostgreSQL (10 or higher)?
We just did a quick (basically 1:1) migration from SQL Server and are trying to update our code to make sure the general migration is possible. This question does not take possible query speed issues into account (see links for more info there.)