Linq to Entities : using ToLower() on NText fields

Posted by Julien N on Stack Overflow See other posts from Stack Overflow or by Julien N
Published on 2010-03-12T10:14:40Z Indexed on 2010/03/12 10:17 UTC
Read the original article Hit count: 664

I'm using SQL Server 2005, with a case sensitive database..

In a search function, I need to create a Linq To Entities (L2E) query with a "where" clause that compare several strings with the data in the database with these rules :

  1. The comparison is a "Contains" mode, not strict compare : easy as the string's Contains() method is allowed in L2E
  2. The comparison must be case insensitive : I use ToLower() on both elements to perform an insensitive comparison.

All of this performs really well but I ran into the following Exception : "Argument data type ntext is invalid for argument 1 of lower function" on one of my fields.

It seems that the field is a NText field and I can't perform a ToLower() on that.
What could I do to be able to perform a case insensitive Contains() on that NText field ?

© Stack Overflow or respective owner

Related posts about c#

Related posts about linq-to-entities