查询的Windows Azure表的存储与多个查询条件 [英] Querying Windows Azure Table Storage with multiple query criteria

查看:195
本文介绍了查询的Windows Azure表的存储与多个查询条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查询在Windows Azure存储表,最初使用 TableQuery.CombineFilters TableQuery< RecordEntity>() 。凡的功能如下:

I'm trying to query a table in Windows Azure storage and was initially using the TableQuery.CombineFilters in the TableQuery<RecordEntity>().Where function as follows:

TableQuery.CombineFilters(
    TableQuery.GenerateFilterCondition("PartitionKey",   QueryComparisons.GreaterThanOrEqual, lowDate),
    TableOperators.And,
    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.LessThanOrEqual, lowDate),
    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, entityId)
));

不幸的是CombineFilters只允许2查询条件最大值。所以我目前做这样的:

Unfortunately CombineFilters only allows 2 query criteria max. So I'm currently doing this:

var tableQuery = new TableQuery<RecordRowEntity>()
            .Where(TableQuery.CombineFilters("PartitionKey", string.Format("(PartitionKey ge '{0}') and (PartitionKey le '{1}') and (RowKey eq '{2}')", low, high, entityId));

有没有做任何其他方式。上午conerned,我做它为present的方式很容易在Azure的API的工作方式的变化。

Is there any other way of doing it. Am conerned that the way I'm doing it at present is vulnerable to changes in the way the Azure Api works.

推荐答案

一个组合过滤器然后可以用另一个过滤器相结合,根据需要重复多次。参见示例示例 - 查询与PartitionKey =所有实体SamplePK和RowKey大于或等于更大的5在<一个href=\"http://blogs.msdn.com/b/windowsazurestorage/archive/2012/11/06/windows-azure-storage-client-library-2-0-tables-deep-dive.aspx\">http://blogs.msdn.com/b/windowsazurestorage/archive/2012/11/06/windows-azure-storage-client-library-2-0-tables-deep-dive.aspx.

A combined filter can then be combined with another filter, repeating as many times as necessary. See the example "Sample – Query all entities with a PartitionKey="SamplePK" and RowKey greater than or equal to "5"" at http://blogs.msdn.com/b/windowsazurestorage/archive/2012/11/06/windows-azure-storage-client-library-2-0-tables-deep-dive.aspx.


string pkFilter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "samplePK");

字符串rkLowerFilter = TableQuery.GenerateFilterCondition(RowKey,QueryComparisons.GreaterThanOrEqual,5);

string rkLowerFilter = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, "5");

字符串rkUpperFilter = TableQuery.GenerateFilterCondition(RowKey,QueryComparisons.LessThan,10);

string rkUpperFilter = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThan, "10");

//注CombineFilters具有([实施例pression1])操作员在一个复杂的前pression效果(实施例pression2]),因为这样的传递将导致的逻辑分组。
字符串combinedRowKeyFilter = TableQuery.CombineFilters(rkLowerFilter,TableOperators.And,rkUpperFilter);

// Note CombineFilters has the effect of "([Expression1]) Operator (Expression2]), as such passing in a complex expression will result in a logical grouping. string combinedRowKeyFilter = TableQuery.CombineFilters(rkLowerFilter, TableOperators.And, rkUpperFilter);

字符串combinedFilter = TableQuery.CombineFilters(pkFilter,TableOperators.And,combinedRowKeyFilter);

string combinedFilter = TableQuery.CombineFilters(pkFilter, TableOperators.And, combinedRowKeyFilter);

// OR
串combinedFilter =的String.Format(({0}){1}({2}){3}({4}),pkFilter,TableOperators.And,rkLowerFilter,TableOperators.And,rkUpperFilter);
TableQuery查询=新TableQuery(),其中(combinedFilter)。

// OR string combinedFilter = string.Format("({0}) {1} ({2}) {3} ({4})", pkFilter, TableOperators.And, rkLowerFilter, TableOperators.And, rkUpperFilter); TableQuery query = new TableQuery().Where(combinedFilter);

这篇关于查询的Windows Azure表的存储与多个查询条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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