gpt4 book ai didi

c# - 从azure表存储中获取所有记录

转载 作者:可可西里 更新时间:2023-11-01 08:07:22 24 4
gpt4 key购买 nike

使用此代码块

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

我能够使用检索中提到的分区和行键检索单个记录。

有没有办法获取存储在 ServiceAlerts 分区中的所有记录?

我尝试使用通配符 (*) 作为第二个参数

TableOperation retrieveOperation = TableOperation.Retrieve<ServiceAlertsEntity>(
"ServiceAlerts","b9ccd839-dd99-4358-b90f-46781b87f933");

但它不会返回任何内容。

最佳答案

您需要指定一个 TableQuery,这将为您提供所有实体,或者您可以指定一个 TableQuery.GenerateFilterCondition 来过滤行。

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

关于c# - 从azure表存储中获取所有记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38748426/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com