Galkin
Galkin

Reputation: 843

Is there any way to get rowKey and patitionKey from Azure TableOperation?

I have a internal Azure TableOperation variable and I need to get rowKey and patitionKey. I know that I can do it by reflation but it the last way I would do. I would be glad to find another way to get this info from TableOperation variable

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)));
}

Upvotes: 0

Views: 241

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136386

AFAIK, using TableOperation it is not possible however table.Execute method return an object of type TableResult. Now TableResult has a property called Result. I tested with Insert, Delete and InsertOrReplace methods and in all of them Result contained the entity on which I performed the operation. Would this work for you?

        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

Upvotes: 1

Related Questions