如何在Azure中执行区分大小写的LINQ查询?

我正在使用Windows Azure存储表,并希望查询对象。 用户输入一个字符串,我在数据库中查找如下:

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

但是,由于某种原因,所有字符串比较似乎都不区分大小写( ==string.Equals() )。 但是,我需要匹配用户输入字符串的确切大小写。

我怎样才能在LINQ查询中执行此操作?

使用==.Equals(..)相同,因为它只调用该方法。 您可以使用传递string.comparison枚举的Equal()重载来强制使用区分大小写的比较

 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. 

更多信息:

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