有没有办法从Azure TableOperation获取rowKey和patitionKey?

时间:2015-08-14 15:12:10

标签: c# azure

我有一个内部Azure TableOperation变量,我需要获取rowKey和patitionKey。我知道我可以通过通货再生来做到这一点,但这是我做的最后一种方式。 我很乐意找到另一种从TableOperation变量

获取此信息的方法
foreach (TableOperation operation in tableOperations)
{
//I need to get RowKey in in this case from operation variable

results.Add(RetryManager.StorageRetryPolicy.ExecuteAction(() => table.Execute(operation)));
}

1 个答案:

答案 0 :(得分:1)

AFAIK,使用TableOperation时无法使用table.Execute方法返回TableResult类型的对象。现在TableResult有一个名为Result的属性。我使用InsertDeleteInsertOrReplace方法进行了测试,并且在所有方法Result中都包含了我执行操作的实体。这对你有用吗?

        var account = new CloudStorageAccount(new StorageCredentials(accountName, accountKey), true);
        var tableClient = account.CreateCloudTableClient();
        var table = tableClient.GetTableReference("Address");
        var entity = new DynamicTableEntity("pk", "rk");
        entity.Properties.Add("Attribute1", new EntityProperty("Attribute 1 Value"));
        TableOperation upsertOperation = TableOperation.InsertOrReplace(entity);
        var tableResult = table.Execute(upsertOperation);
        var result = tableResult.Result;
        Console.WriteLine(result.GetType());//Prints Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity
        var deleteOperation = TableOperation.Delete(entity);
        tableResult = table.Execute(deleteOperation);
        result = tableResult.Result;
        Console.WriteLine(result.GetType());//Prints Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity
        var insertOperation = TableOperation.Insert(entity, false);
        tableResult = table.Execute(insertOperation);
        result = tableResult.Result;
        Console.WriteLine(result.GetType());//Prints Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity