I am trying to filter a list by a search string. It says in the doc on the blue note that:
- IQueryable gives you the database provider implementation of
Contains
. IEnumerable
gives you the .NET Framework implementation ofContains
- The default setting of SQL Server instances is case-insensitive.
- Using
ToUpper
to make an explicit case-insensitive call should be avoided because it has a performance penalty.
My filtering is as follows:
IQueryable<ApplicationUser> customers =
from u in _context.Users
where (u.Customer != null && u.IsActive)
select u;
if (!string.IsNullOrEmpty(searchString))
{
customers = customers.Where(s => s.Email.Contains(searchString));
}
This solution however is case-sensitive, and I don't really understand why: since I'm using IQueryable
, it should use the database provider implementation, that is case-insensitive by default, right?
I'm using EF Core 2 and currently just running a local MSSQLLocalDB.
string
processing in .Net have little relevance to LINQ to SQL queries. – Denticulation