有一种方法可以从TableOperation参数中获取PartitionKey和RowKey
public override Task<TableResult> ExecuteAsync(TableOperation operation)
{
switch (operation.OperationType)
{
case TableOperationType.Retrieve:
//entityResult = Get<ITableEntity>(operation.PartitionKey, operation.RowKey);
break;
}
}
答案 0 :(得分:0)
Azure Table Storage Document进行了以下介绍:
PartitionKey属性:
对表进行分区以支持跨存储节点的负载平衡。表的实体按分区组织。分区是拥有相同分区键值的实体的连续范围。分区键是给定表中分区的唯一标识符,由PartitionKey
属性指定。分区键构成实体主键的第一部分。分区键可以是最大1 KB的字符串值。
您必须在每个插入,更新和删除操作中包含PartitionKey
属性
操作。
RowKey属性:
主键的第二部分是行键,由RowKey
属性指定。行键是给定分区中实体的唯一标识符。 PartitionKey
和RowKey
共同唯一地标识表中的每个实体。
行键是一个字符串值,最大长度为1 KB。
每个插入,更新和删除操作中都必须包含RowKey
属性。
因此,我们必须在每个插入,更新和删除操作中包括PartitionKey
和RowKey
属性。
TableOperation.Retrieve
重载了三种方法:
无论哪个Retrieve
,都需要PartitionKey
和RowKey
:
您无法从TableOperation Retrieve操作中获取PartionKey
和RowKey
。
创建TableOperation
时,它应包含实体的PartionKey
和RowKey
。
例如:
TableOperation retrieveOperation = TableOperation.Retrieve<CustomerEntity>("Smith", "Ben");
但是在您的方法中,TableOperation operation
是一个参数,因此Entity
是null
。
希望这可以为您提供帮助。
答案 1 :(得分:0)
是的,你可以,但你需要使用反射,可能还有另一种选择,但反射仍然是简单的实现
例如:var rowKey = GetField(tableOperationObject, "RowKey");
private string GetField(TableOperation operation, string field)
{
PropertyInfo highlightedItemProperty = operation.GetType()
.GetProperties(BindingFlags.NonPublic | BindingFlags.Instance).Single(pi => pi.Name == field);
object value = highlightedItemProperty.GetValue(operation, null);
return value?.ToString();
}