How to execute case-sensitive LINQ query in Azure?

I am using Windows Azure storage tables and want to query an object. The user enters the string I'm looking for in the database as such:

var myKey = "SomeCaseSensitiveKeyInputByTheUser"; var someObject = (from o in dataContext.Objects where o.SomeString.Equals(myKey) select o).FirstOrDefault(); 

However, for some reason, all string comparisons look case insensitive (both == and string.Equals() ). However, I need to map the exact shell of the user input line.

How can I do this in my LINQ query?

+1
c # linq azure azure-table-storage
source share
1 answer

Using == same as .Equals(..) since it just calls this method. You can force case-insensitive comparisons using the Equal () overload passing string.comparison enum

 CurrentCulture Compare strings using culture-sensitive sort rules and the current culture. CurrentCultureIgnoreCase Compare strings using culture-sensitive sort rules, the current culture, and ignoring the case of the strings being compared. InvariantCulture Compare strings using culture-sensitive sort rules and the invariant culture. InvariantCultureIgnoreCase Compare strings using culture-sensitive sort rules, the invariant culture, and ignoring the case of the strings being compared. Ordinal Compare strings using ordinal sort rules. OrdinalIgnoreCase Compare strings using ordinal sort rules and ignoring the case of the strings being compared. 

Additional Information:

http://msdn.microsoft.com/en-us/library/system.stringcomparison.aspx

+1
source share

All Articles