使用 C# 创建一个控制台应用程序,以从 Azure 表存储中读取数据。

问题描述 投票:0回答:1

请推荐关于创建从Azure表存储读取数据的控制台应用程序的好文档。我遵循了 https:/www.youtube.comwatch?v=z96fIv3RQBo 并创建了一个示例控制台应用程序,如下所示。在运行控制台时,我看到'ReceivedBadRequest'错误。

class Program
    {
        const string StorageAccountName = "";
        const string StorageAccountKey = "";

        static void Main(string[] args)
        {
            var storageAccount = new CloudStorageAccount(new StorageCredentials(StorageAccountName, StorageAccountKey), false);
            var tableaa = storageAccount.CreateCloudTableClient().GetTableReference("Table1");
            var result = tableaa.ExecuteAsync(TableOperation.Retrieve<Person>("<partition-key>", "<row-key>"));
            var entity = result.Result;
            Console.WriteLine(entity);
        }
    }

    class Person : TableEntity
    {
        private int customerID;
        private string LocationAreaCode;
        private string PersonnelSubAreaCode;
        private string PersonStatusCode;
        public void AssignRowKey()
        {
            this.RowKey = customerID.ToString();
        }
        public void AssignPartitionKey()
        {
            this.PartitionKey = "<partition-key";
        }    
    }
c# azure-table-storage
1个回答
1
投票

你的Person类中缺少一个无参数的构造函数。

请按以下方式修改Person类。

class Person : TableEntity
{
    private int customerID;
    private string LocationAreaCode;
    private string PersonnelSubAreaCode;
    private string PersonStatusCode;

    public Person()
    {

    }

    //other code


}

更多细节,请参考这个 正式文件.

© www.soinside.com 2019 - 2024. All rights reserved.