1

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

var myKey = "SomeCaseSensitiveKeyInputByTheUser";

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

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

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

4

1 回答 1

1

Using==与 相同.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

于 2012-05-22T13:47:36.497 回答