如何执行在Azure中的区分大小写的LINQ查询? [英] How to perform a case-sensitive LINQ query in Azure?

查看:160
本文介绍了如何执行在Azure中的区分大小写的LINQ查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Windows Azure存储表,并希望查询的对象。用户输入一个字符串,这是我在数据库中寻找这样:

I am using Windows Azure Storage Tables, and want to query for an object. 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();

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

However, for some reason, all string comparisons appear to be case insensitive (both == and string.Equals()). However, I need to match the exact casing of the user input string.

我怎样才能做到这在我的LINQ查询?

How can I do this in my LINQ query?

推荐答案

使用 == 相同 .Equals(..),因为它只是调用这个方法。
您可以强制使用用平等(过载)传递一个区分大小写比较的 string.comparison 枚举

Using == is the same as .Equals(..), as it just calls that method. You can force to use a case sensitive comparison using an overload of Equal() passing a 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/库/ system.stringcomparison.aspx

这篇关于如何执行在Azure中的区分大小写的LINQ查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆