点查询天蓝色存储表

时间:2020-06-09 12:38:57

标签: c# azure xamarin

当我尝试此代码时

 public static async  Task<CustomerEntity> RetrieveEntityUsingPointQueryAsync(CloudTable table, string partitionKey, string rowKey)
    {
        try
        {
            TableOperation retrieveOperation = TableOperation.Retrieve<CustomerEntity>(partitionKey, rowKey);
            TableResult result = await table.ExecuteAsync(retrieveOperation);
            CustomerEntity customer = result.Result as CustomerEntity;

            if (customer != null)
            {
                Console.WriteLine("\t{0}\t{1}\t{2}\t{3}", customer.PartitionKey, customer.RowKey, customer.Email, customer.PhoneNumber);
            }

            // Get the request units consumed by the current operation. RequestCharge of a TableResult is only applied to Azure CosmoS DB 
            if (result.RequestCharge.HasValue)
            {
                Console.WriteLine("Request Charge of Retrieve Operation: " + result.RequestCharge);
            }

            return customer;
        }
        catch (StorageException e)
        {
            Console.WriteLine(e.Message);
            Console.ReadLine();
            throw;
        }
    }

TableQuery通用类型必须提供默认的无参数 构造函数Microsoft.Azure.Cosmos.Table.StorageException

1 个答案:

答案 0 :(得分:1)

错误消息指出,您需要为CustomerEntity类使用无参数构造函数。

只需在您的CustomerEntity类中添加以下代码,即可解决此问题:

public CustomerEntity()
{     
}