I would like to query my azure tablestorage using PrimaryKey plus I would like to check my RowKey is within a range. For example the range 02001 to 02999
Can someone tell me how I can do this? I understand how to query the PK with a simple:
where fooEntiy.PartitionKey == partition
but I don't know how I can query fooEntity.RowKey.
Also if I do this by specifying a range then will it still retrieve all the entries for that partition and then check to see if they match the range?
Thank you for your advice,
Mariko
The row key is a unique identifier for an entity within a given partition. Together the PartitionKey and RowKey uniquely identify every entity within a table. The row key is a string value that may be up to 1 KiB in size. You must include the RowKey property in every insert, update, and delete operation.
By default a property is created as type String , unless you specify a different type. To explicitly type a property, specify its data type by using the appropriate OData data type for an Insert Entity or Update Entity operation. For more information, see Inserting and Updating Entities.
Azure Table Storage supports a single region with an optional read-only secondary region for availability. Cosmos DB supports distribution from 1 to more than 30 regions with automatic failovers worldwide.
Your query could look something like this:
where fooEntity.PartitionKey == partionKey
&& fooEntity.RowKey.CompareTo(lowerBoundRowKey) >= 0
&& fooEntity.RowKey.CompareTo(upperBoundRowKey) <= 0
This should return all of the items between the lowerBoundRowKey
and the upperBoundRowKey
including those values (if you don't want it to be inclusive, just use > and < rather than >= and <=).
You will not need to do any other filtering than this.
It looks like you're already padding your numbers that you're storing in the RowKey with leading zeros which is a good thing as this range will be a lexical range, not a numeric range.
e.g. running this query with lowerBoundKey = 10
and upperBoundKey = 100
will not return an item with a RowKey of 20.
If you pad it with zeros however lowerBoundKey = 00010
and upperBoundKey = 00100
will return an item with a RowKey of 00020.
This will bring entities using the specified range of RowKey values with specified PartitionKey:
" PartitionKey eq 'your partitonKey value' and (RowKey gt '02001' and RowKey lt '02999') "
Find more information here and here. Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With