1

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 can find

It couldn't find data with lower case letter. enter image description here

cagin
  • 5,772
  • 14
  • 74
  • 130
  • If you take a look at this previous question should get you going [1]: http://stackoverflow.com/questions/3069241/make-entity-framework-be-case-insensitive – mreyeros Jan 11 '13 at 19:18

2 Answers2

3

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();
}
jrummell
  • 42,637
  • 17
  • 112
  • 171
1

Try this instead :

return context.GetActiveProducts().Where(p => 
          p.Name.IndexOf(name,StringComparison.OrdinalIgnoreCase) >= 0).ToList();

This will fix your issue.

Kundan Singh Chouhan
  • 13,952
  • 4
  • 27
  • 32