使用retrieve <entity>后,为什么无法访问单个实体的属性?

时间:2017-06-30 04:45:54

标签: .net asp.net-mvc azure azure-table-storage

TableOperation retrieve = TableOperation.Retrieve<CustomerEntity>("PartitionKeyvalue", "Rowkey");
TableResult result = table.Execute(retreive);

现在这个单一实体有属性,为什么我不能像result.Result.(Property)那样访问它们?

我是否需要遍历TableResult中存储的单个实体?

1 个答案:

答案 0 :(得分:1)

https://docs.microsoft.com/en-us/azure/storage/storage-dotnet-how-to-use-tables#retrieve-a-single-entity

请使用通用方法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.");
}