HHH
HHH

Reputation: 6465

How to retrieve multiple entries with the same partition key in Azure Table?

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.

Upvotes: 4

Views: 3854

Answers (2)

Jeff Nall
Jeff Nall

Reputation: 44

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

Upvotes: -1

jehine-MSFT
jehine-MSFT

Reputation: 240

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.

Upvotes: 3

Related Questions