在Azure表存储服务中查询PartitionKey和RowKey语法
同时,在Microsoft文档上读取Azure表存储服务时,我发现myaccount.Table.core.windows.net URL中的在Azure表存储服务中查询PartitionKey和RowKey语法,azure,rest,azure-storage,azure-table-storage,Azure,Rest,Azure Storage,Azure Table Storage,同时,在Microsoft文档上读取Azure表存储服务时,我发现myaccount.Table.core.windows.net URL中的PartitionKey和RowKeys可以通过两种不同的方式进行过滤,如下所示: https://<service-url>/Customers(PartitionKey='MyPartition',RowKey='MyRowKey1') 我从文档中了解到,PartitionKey和RowKey属性构成实体的主键,因此可以使用第一种语法以及
PartitionKey
和RowKeys
可以通过两种不同的方式进行过滤,如下所示:
https://<service-url>/Customers(PartitionKey='MyPartition',RowKey='MyRowKey1')
我从文档中了解到,PartitionKey
和RowKey
属性构成实体的主键,因此可以使用第一种语法以及零件状态:
由于PartitionKey和RowKey属性构成实体的主键,因此可以使用特殊语法来标识实体
问题:
$filter
而不是前面提到的那种特殊语法有什么缺点和缺点吗感谢您的澄清 有趣的问题!因此,我尝试使用Postman执行两种操作来获取实体,获取数据所需的时间几乎相同(在250ms到300ms之间) 所以,只要您使用的是RESTAPI,我认为这并不重要 当您使用SDK(例如WindowsAzure.Storage 9.3.3版)时,有不同的方法使用这些功能。请看下面的示例代码:
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();
您是否使用任何SDK获取实体或直接调用REST API?@GauravMantri直接调用REST API我假设,目前正在阅读文档。这是一个理论问题。我希望这能澄清问题。
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();