Reputation: 5930
I use contains clause for searching in db table. But if the data has upper case letter and if I search with lower cases, it doesn't find what I search. But it can find when I search with upper case letter. It is the same with lower case searches.
Here is my code:
using (var context = new eTicaretEntity())
{
return context.GetActiveProducts().Where(p => p.Name.Contains(name)).ToList();
}
And you can see what I mean is these pics.
It can find with upper case letter.
It couldn't find data with lower case letter.
Upvotes: 1
Views: 815
Reputation: 14302
Try this instead :
return context.GetActiveProducts().Where(p =>
p.Name.IndexOf(name,StringComparison.OrdinalIgnoreCase) >= 0).ToList();
This will fix your issue.
Upvotes: 1
Reputation: 43087
If your database collation is case sensitive, then you'll have to convert both sides of the comparison to upper (or lower) case.
using (var context = new eTicaretEntity())
{
return context.GetActiveProducts()
.Where(p => p.Name.ToUpper().Contains(name.ToUpper()))
.ToList();
}
Upvotes: 3