Print Page | Close Window

Case InSensitive string Query

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2081
Printed Date: 10-Jun-2026 at 5:03pm


Topic: Case InSensitive string Query
Posted By: EisenbergEffect
Subject: Case InSensitive string Query
Date Posted: 20-Aug-2010 at 11:05am
I would like to use linq to query for all Persons with a certain Name. However, I would like to do this in a case insensitive way. Currently, I am using Name.Contains(searchText), but that isn't working.



Replies:
Posted By: bennage
Date Posted: 20-Aug-2010 at 2:37pm
Some additional information about this problem. The db is case insensitive.
I'm catching the generated SQL with EFPRof and when I run it manually I get a row back. Is DevForce possibly filtering the results from the db?


Posted By: ting
Date Posted: 20-Aug-2010 at 4:14pm

Our next build will have queries set to the SQL Server defaults (case insensitive, ignore trailing whitespace), and will have options for you to configure the behavior if you need something different.

In the meantime, you can perform the query like this:
entityManager.Employees.Where(emp => emp.FirstName.Equals("Kathy", StringComparison.CurrentCultureIgnoreCase);
 


Posted By: EisenbergEffect
Date Posted: 20-Aug-2010 at 4:46pm
That will work in the mean time. Thanks!


Posted By: EisenbergEffect
Date Posted: 23-Aug-2010 at 7:00am
Unfortunately, this solution does not work. It causes a serialization error:

There was an error while trying to serialize parameter http://ideablade.com/EntityModel:entityQuerySurrogate. The InnerException message was 'Type 'System.StringComparison' with data contract name 'StringComparison:http://schemas.datacontract.org/2004/07/System' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'.  Please see InnerException for more details.

Getting this simple scenario working is *critical* for our application. I'm using version 6.0.4


Posted By: WardBell
Date Posted: 23-Aug-2010 at 10:24am
The technique definitely works ... on all of our machines. Something is not quite right in your environment. Following up with you outside the forum. I'll be back with the resolution for our genernal audience.


Posted By: kimj
Date Posted: 23-Aug-2010 at 11:20am
We added support for serialization of the StringComparison type in 6.0.5.  You can work around this now by adding this as a known type; see my reply here - http://www.ideablade.com/forum/forum_posts.asp?TID=2080 - http://www.ideablade.com/forum/forum_posts.asp?TID=2080 .


Posted By: EisenbergEffect
Date Posted: 23-Aug-2010 at 12:26pm
That did it! Thanks!


Posted By: WardBell
Date Posted: 23-Aug-2010 at 12:31pm
Hey great. I blamed the customer for not having the proper environment ... like mine ... like DF preview bits that you couldn't possibly have. Sorry about that!



Print Page | Close Window