[英]How to perform a case-sensitive LINQ query in Azure?
I am using Windows Azure Storage Tables, and want to query for an object. 我正在使用Windows Azure存储表,并想查询一个对象。 The user inputs a string, which I look for in the database as such:
用户输入一个字符串,我在数据库中这样查找:
var myKey = "SomeCaseSensitiveKeyInputByTheUser";
var someObject = (from o in dataContext.Objects
where o.SomeString.Equals(myKey)
select o).FirstOrDefault();
However, for some reason, all string comparisons appear to be case insensitive (both ==
and string.Equals()
). 但是,由于某种原因,所有字符串比较似乎都不区分大小写(
==
和string.Equals()
)。 However, I need to match the exact casing of the user input string. 但是,我需要匹配用户输入字符串的确切大小写。
How can I do this in my LINQ query? 如何在LINQ查询中执行此操作?
Using ==
is the same as .Equals(..)
, as it just calls that method. 使用
==
与.Equals(..)
相同,因为它只是调用该方法。 You can force to use a case sensitive comparison using an overload of Equal() passing a string.comparison
enum 您可以通过传递
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.
more info at: 更多信息,请访问:
http://msdn.microsoft.com/en-us/library/system.stringcomparison.aspx http://msdn.microsoft.com/en-us/library/system.stringcomparison.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.