为什么在使用 retrieve <entity> 后无法访问单个实体的属性?
Why can´t I access the properties of a single entity after using retrieve <entity>?
TableOperation retrieve = TableOperation.Retrieve<CustomerEntity>("PartitionKeyvalue", "Rowkey");
TableResult result = table.Execute(retreive);
现在这个单一实体有了属性,那为什么我不能像 result.Result.(Property)
那样访问它们?
我是否需要遍历存储在 TableResult
中的单个实体?
请使用通用方法 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.");
}
TableOperation retrieve = TableOperation.Retrieve<CustomerEntity>("PartitionKeyvalue", "Rowkey");
TableResult result = table.Execute(retreive);
现在这个单一实体有了属性,那为什么我不能像 result.Result.(Property)
那样访问它们?
我是否需要遍历存储在 TableResult
中的单个实体?
请使用通用方法 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.");
}