I’m trying to filter a list of objects using linq. When i filter by a Contains(someSearchQuery) it’s like it’s being case sensitive .. meaning i miss some results.
I have an IList<Foo>‘s which has a number of properties, but one is public string MyText { get; set; }
Now, i’m trying to return a IQueryable of Foo’s where the MyText property contain the search query – but as a If this was a Sql statement, it would be either..
WHERE MyText LIKE '%searchQuery%' <– Works but inefficent
or
WHERE CONTAINS(MyText, 'searchQuery') <– using FTS.
I’m not sure how to do this, because when I do the following query it’s like it’s doing a case sensitive
var query = from q in myFooList.AsQueryable().Where(x => x.MyText.Contains(searchQuery));
Suggestions?
You’re asking about the
string.Containsmethod, not about LINQ.String.Containsdoes not support case-insensitive searching. Instead, you should callIndexOf, like this:Note that since you’re using LINQ-to-Objects, you (presumably) don’t need
AsQueryable.