SQL Server default compatibility is case insensitive, which means where clause like this (this is what LINQ to Entities will create from Contains ) ...
where Name like '%JOHN%'
... should find "john Wayne". I believe that your request is not executed on the server, but in fact with LINQ to Objects in memory - and there the search is case sensitive. This is LINQ to Objects because you are not returning Expression from your BlogPostContains . Signature must be:
private Expression<Func<BlogPost, bool>> BlogPostContains(string query)
If you return only Func<BlogPost, bool> , you are working with an IEnumerable (and not IQueryable ) overload of the Where extension method, which in turn first loads the entire BlogPosts table into memory. The filter is then applied in memory with LINQ to Objects.
It would be interesting to know if case sensitivity disappears if you return Expression .
(As a note about your case-sensitivity problem, not a solution to the general question of the best way to implement the search function.)
source share