简体   繁体   English

AzureStorage 表查询:构建包含筛选器

[英]AzureStorage Table Query: Building a Contains Filter

I'm aware that Azure Storage doesn't have a contains like filter in their current API.我知道 Azure 存储在其当前 API 中没有包含类似过滤器。 However, I also know that you can build a contains like filter for strings using code like the following:但是,我也知道您可以使用如下代码为字符串构建一个类似 contains 的过滤器:

            TableQuery<TableEntity> Query = new TableQuery<TableEntity>()
            .Where(
            TableQuery.CombineFilters(
                TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.GreaterThanOrEqual, substring),
                TableOperators.And,
                TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.LessThan, substring + someValue)
                ));

My Question is what should I use as someValue to make this equivalent to a contains?我的问题是我应该使用什么作为 someValue 来使其等效于包含?

I can't seem to find a chart online that indicates what char is the first char for all chars lexigraphically for c#.我似乎无法在网上找到一个图表,该图表表明 c# 的所有字符的第一个字符是什么字符。 Is there any reason not to do this, and do the search on the client side?有什么理由不这样做,并在客户端进行搜索吗? My partitionKey is well defined subgroups.我的 partitionKey 是定义明确的子组。

Thanks in advance!提前致谢!

It actually uses the ascii order to compare in the filter.它实际上使用ascii顺序在过滤器中进行比较。

For example, if the substring is good , then in the second filter:例如,如果substringgood ,则在第二个过滤器中:

TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.LessThan, "good" + someValue) , TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.LessThan, "good" + someValue) ,

you should change it to你应该把它改成

TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.LessThan, "gooe")

There is no need to add someValue .无需添加someValue Just replace the last char for your substring, to the next ascii char.只需将子字符串的最后一个字符替换为下一个 ascii 字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM