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

时间:2012-05-22 13:34:02

标签: c# linq azure azure-table-storage

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

var myKey = "SomeCaseSensitiveKeyInputByTheUser";

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

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

如何在LINQ查询中执行此操作?

1 个答案:

答案 0 :(得分:1)

使用==.Equals(..)相同,因为它只调用该方法。 您可以使用Equal()传递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