本文介绍了从Azure表存储中获取所有记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用此代码块
try
{
StorageCredentials creds = new StorageCredentials(accountName, accountKey);
CloudStorageAccount account = new CloudStorageAccount(creds, useHttps: true);
CloudTableClient client = account.CreateCloudTableClient();
CloudTable table = client.GetTableReference("serviceAlerts");
TableOperation retrieveOperation = TableOperation.Retrieve<ServiceAlertsEntity>("ServiceAlerts", "b9ccd839-dd99-4358-b90f-46781b87f933");
TableResult query = table.Execute(retrieveOperation);
if (query.Result != null)
{
outline = outline + ((ServiceAlertsEntity) query.Result).alertMessage + " * ";
}
else
{
Console.WriteLine("No Alerts");
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
我能够使用检索中提到的分区和行键来检索单个记录.
I am able to retrieve the single record with the partition and rowkey mentioned in the retrieve.
有没有一种方法可以获取存储在ServiceAlerts分区中的所有记录?
Is there a way I can get all the records that are stored in the partition of ServiceAlerts?
我尝试为第二个参数使用通配符(*)
I have tried a wildcard (*) for the second parameter
TableOperation retrieveOperation = TableOperation.Retrieve<ServiceAlertsEntity>(
"ServiceAlerts","b9ccd839-dd99-4358-b90f-46781b87f933");
但它不会返回任何内容.
but it does not return anything.
推荐答案
您需要指定一个TableQuery,这将为您提供所有实体,或者您可以指定TableQuery.GenerateFilterCondition
来过滤行.
You need to specify a TableQuery, this will give you all entities or you can specify a TableQuery.GenerateFilterCondition
to filter the rows.
TableQuery<ServiceAlertsEntity> query = new TableQuery<ServiceAlertsEntity>();
foreach (ServiceAlertsEntity entity in table.ExecuteQuery(query))
{
Console.WriteLine("{0}, {1}\t{2}\t{3}", entity.PartitionKey, entity.RowKey,
entity.Field1, entity.Field2);
}
这篇关于从Azure表存储中获取所有记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!