使用 C# 创建控制台应用程序以从 Azure Table 存储读取数据
Create a console application to read data from Azure Table Storage using C#
请推荐有关创建用于从 Azure Table 存储读取数据的控制台应用程序的良好文档。我按照 https://www.youtube.com/watch?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";
}
}
您的 Person 中缺少无参数构造函数 class:
请将人物 class 更改如下:
class Person : TableEntity
{
private int customerID;
private string LocationAreaCode;
private string PersonnelSubAreaCode;
private string PersonStatusCode;
public Person()
{
}
//other code
}
详情请参考此official doc。
请推荐有关创建用于从 Azure Table 存储读取数据的控制台应用程序的良好文档。我按照 https://www.youtube.com/watch?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";
}
}
您的 Person 中缺少无参数构造函数 class:
请将人物 class 更改如下:
class Person : TableEntity
{
private int customerID;
private string LocationAreaCode;
private string PersonnelSubAreaCode;
private string PersonStatusCode;
public Person()
{
}
//other code
}
详情请参考此official doc。