使用多个查询条件查询Windows Azure表存储

Cap*_*ohn 13 azure azure-table-storage data-partitioning

我正在尝试查询Windows Azure存储中的表,并且最初TableQuery.CombineFiltersTableQuery<RecordEntity>().Where函数中使用如下:

TableQuery.CombineFilters(
    TableQuery.GenerateFilterCondition("PartitionKey",   QueryComparisons.GreaterThanOrEqual, lowDate),
    TableOperators.And,
    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.LessThanOrEqual, lowDate),
    TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, entityId)
));
Run Code Online (Sandbox Code Playgroud)

不幸的是,CombineFilters最多只允许2个查询条件.所以我现在正在这样做:

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));
Run Code Online (Sandbox Code Playgroud)

有没有其他方法可以做到这一点.我认为目前我正在这样做的方式很容易受到Azure Api工作方式的影响.

kwi*_*ill 25

然后可以将组合滤波器与另一个滤波器组合,根据需要重复多次.请参阅示例"示例 - 使用PartitionKey查询所有实体="SamplePK"和RowKey大于或等于"5"",网址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");

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

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

// 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);

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

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