我正在使用Windows Azure存储表,并且想要查询对象。用户输入一个字符串,我在数据库中查找:
var myKey = "SomeCaseSensitiveKeyInputByTheUser";
var someObject = (from o in dataContext.Objects
where o.SomeString.Equals(myKey)
select o).FirstOrDefault();
但是,出于某种原因,所有字符串比较似乎都不区分大小写(==
和string.Equals()
)。但是,我需要匹配用户输入字符串的确切大小。
如何在LINQ查询中执行此操作?
答案 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