2012-05-22 34 views
1

我正在使用Windows Azure存储表,并且想要查询对象。用户输入一个字符串,这是我在数据库中寻找这样:如何在Azure中执行区分大小写的LINQ查询?

var myKey = "SomeCaseSensitiveKeyInputByTheUser"; 

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

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

我该如何在我的LINQ查询中做到这一点?

+0

你有没有尝试使用平等的StringComparison超载? 所以像i.SomeString.Equals(mykey,StringComparer.CurrentCulture) –

回答

1

使用==.Equals(..)相同,因为它只是调用该方法。 您可以强制使用用平等(过载)传递一个string.comparison枚举

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

+0

我曾尝试过重载,但事实证明我在其他地方犯了一个非常愚蠢的错误。 CurrentCulture最终做到了这一招。谢谢。 –