TableOperation retrieve = TableOperation.Retrieve<CustomerEntity>("PartitionKeyvalue", "Rowkey");
TableResult result = table.Execute(retreive);
现在这个单一实体有属性,为什么我不能像result.Result.(Property)
那样访问它们?
我是否需要遍历TableResult
中存储的单个实体?
答案 0 :(得分:1)
请使用通用方法Retrieve()来指定实体的类型:
// Retrieve the storage account from the connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the table client.
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
// Create the CloudTable object that represents the "people" table.
CloudTable table = tableClient.GetTableReference("people");
// Create a retrieve operation that takes a customer entity.
TableOperation retrieveOperation = TableOperation.Retrieve<CustomerEntity>("Smith", "Ben");
// Execute the retrieve operation.
TableResult retrievedResult = table.Execute(retrieveOperation);
// Print the phone number of the result.
if (retrievedResult.Result != null)
{
Console.WriteLine(((CustomerEntity)retrievedResult.Result).PhoneNumber);
}
else
{
Console.WriteLine("The phone number could not be retrieved.");
}