query no case sensitive with Contains string

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
ratm
Posts: 13
Joined: Thu 14 Feb 2019 11:36

query no case sensitive with Contains string

Post by ratm » Sat 23 Mar 2019 08:38

Hi, can anyone tell me how you can make it so that in the non-match between strings it's not case sensitive in a query?
var list = (from p in context.Patient
                         where p.Name.Contains (query) || p.Cognome.Contains (query)
                         orderby p.Name, p.Cognome
                         select p) .ToList ();
In this query the contains is case sensitive and therefore does not return a correct result. how can I do?

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: query no case sensitive with Contains string

Post by Shalex » Mon 25 Mar 2019 16:14

Try this way:

Code: Select all

p.Name.Contains("some string")

->

p.Name.ToUpper().Contains("some string".ToUpper())

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: query no case sensitive with Contains string

Post by Shalex » Tue 26 Mar 2019 10:51

One more solution is to change the column data type to citext: https://www.postgresql.org/docs/current/citext.html.

Post Reply