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

2023-12-06

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

var myKey = "SomeCaseSensitiveKeyInputByTheUser";

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

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

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


Using ==是相同的.Equals(..),因为它只是调用该方法。 您可以使用 Equal() 的重载传递一个值来强制使用区分大小写的比较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.

更多信息请访问:

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

随机推荐