[英]Check if a row exists in Azure Storage Table using the Azure.Data.Tables.TableClient
I'm using Azure.Data.Tables.TableClient
(also looked at Azure.Data.Tables.TableServiceClient
).我正在使用Azure.Data.Tables.TableClient
(也查看了Azure.Data.Tables.TableServiceClient
)。
I want to check if a record exists in the Azure Table given a specific Partition Key and Row Key.我想检查给定特定分区键和行键的 Azure 表中是否存在记录。 Calling the TableClient.GetEntity<T>
throws an exception if it gets 404 from the server rather than returning null.如果从服务器获取 404 而不是返回 null,则调用TableClient.GetEntity<T>
会引发异常。
I've searched on SO and there is one solution available but it uses the older CloudTable
.我搜索过 SO 并且有一个可用的解决方案,但它使用旧的CloudTable
。
I've tried looking at the TableServiceClient
options but so far haven't had any success finding a good solution that doesnt require catching the exception.我已经尝试查看TableServiceClient
选项,但到目前为止还没有成功找到不需要捕获异常的好的解决方案。
You can probably use Query
and specify your query as PartitionKey eq 'partition-key-value' and RowKey eq 'row-key-value'
.您可能可以使用Query
并将查询指定为PartitionKey eq 'partition-key-value' and RowKey eq 'row-key-value'
。
If the entity does not exist, you will receive an empty array back instead of error.如果该实体不存在,您将收到一个空数组而不是错误。 If the entity exists, you will receive an array with just 1 entity.如果该实体存在,您将收到一个只有 1 个实体的数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.