代码之家  ›  专栏  ›  技术社区  ›  Mrinal Das

为什么在使用retrieve后无法访问单个实体的属性?

  •  1
  • Mrinal Das  · 技术社区  · 8 年前
    TableOperation retrieve = TableOperation.Retrieve<CustomerEntity>("PartitionKeyvalue", "Rowkey");
    TableResult result = table.Execute(retreive);
    

    既然这个实体有属性,那么为什么我不能像这样访问它们呢 result.Result.(Property)

    TableResult

    1 回复  |  直到 8 年前
        1
  •  1
  •   Zhaoxing Lu    8 年前

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