Meanwhile reading querying tables and entities in Azure Table Storage service on Microsoft docs I found PartitionKey
and RowKeys
can be filtered in 2 different ways in the myaccount.table.core.windows.net URL as the following:
https://<service-url>/Customers(PartitionKey='MyPartition',RowKey='MyRowKey1')
And using $filter
to achieve the same:
https://<service-url>/Customers()?$filter=PartitionKey%20eq%20'MyPartitionKey'%20and%20RowKey%20eq%20'MyRowKey1'
I understand from the documentation PartitionKey
and RowKey
properties are forming the entity's primary key so the first syntax can be used as well as the Filtering on the PartitionKey and RowKey Properties part states:
Because the PartitionKey and RowKey properties form an entity's primary key, you can use a special syntax to identify the entity.
Questions:
$filter
instead of that special syntax what has been mentioned?Any clarification is appreciated, thank you!
Interesing question! So I tried to perform both the operations to fetch an entity using Postman and the time it took to get the data was almost identical (between 250ms - 300ms).
So as long as you're using REST API, I don't think it would matter.
When you use the SDK (WindowsAzure.Storage version 9.3.3 for example), there're different methods that uses these features. Take a look at the sample code below:
var account = new CloudStorageAccount(new StorageCredentials(accountName, accountKey), true);
var tableClient = account.CreateCloudTableClient();
var table = tableClient.GetTableReference("TableName");
//This uses https://account.table.core.windows.net/table(PartitionKey='pk', RowKey='rk')
TableOperation op = TableOperation.Retrieve("pk", "rk");
var entity = table.Execute(op).Result as DynamicTableEntity;
//This uses https://account.table.core.windows.net/table?$filter=PartitionKey eq 'pk' and RowKey eq 'rk'
TableQuery query = new TableQuery();
query.FilterString = "PartitionKey eq 'pk' and RowKey eq 'rk'";
var entity = table.ExecuteQuery(query).FirstOrDefault();