4
votes

I want to retrieve multiple entries that have the same partition key but different row key from Azure Table Storage. My assumption is it is more efficient that retrieving them one by one. I want to specify a combined query using multiple rowFilters. However TableQuery.combineFilters only takes one filter. How can I do that? I'm following the Retrieve a range of entities in a partition from Azure Table documentation.

2

2 Answers

3
votes

You can query for multiple rows with the same partition key but you would need to use the > and < filters on the rowkey in addition to an == filter on the partition key. There isn't a way to cherry pick a few different rows in one request. You would need to search for a range. You may be able to design your rowkeys in such that you group related rows more closely thus limiting the number of rows you retrieve.

-1
votes

About 1/2 way down this page I think you'll find exactly the answer you're looking for:

Tables Deep Dive

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<SampleEntity> query = new TableQuery<SampleEntity>().Where(combinedFilter);