Case Insensitive Contains Dynamic Linq

When using Contains with Dynamic Linq on Linq-to-objects, the search is case sensitive. I would like to be able to search for case insensitivity (e.g. Linq-to-sql, because SQL Server does this by default).

Sort of:

 this.someQuery = this.someQuery.Where(field + ".Contains(@0, true)", strValue); 

where true means: caseinsensitive = true , like one of the extensions to System.String.Contains . Although I can not use extensions to System.String with dynamic Linq by default.

+6
source share
1 answer

Can you just .ToLower () both sides of the comparison? Something like that:

 this.someQuery = this.someQuery.Where(field.ToLower().Contains(strValue.ToLower())); 

Or did I misunderstand what you were looking for?

+13
source

Source: https://habr.com/ru/post/902108/


All Articles