Azure表:检索整个表

时间:2016-07-30 19:34:03

标签: c# azure azure-table-storage azure-tablequery

我知道如何从Azure表中获取一些表实体,如下所示:

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting(...);
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
CloudTable table = tableClient.GetTableReference("table");
TableOperation retrieveOperation = TableOperation.Retrieve(...);
TableResult retrievedResult = table.Execute(retrieveOperation);

TableQuery<MyEntity> query = new TableQuery<MyEntity>().Where(TableQuery.GenerateFilterCondition(...);

但我想知道:有一种很好的方法来检索整个表吗?

1 个答案:

答案 0 :(得分:3)

您可以使用TableQuery来获取整个表格。

var list = new List<MyEntity>();
var table = tableClient.GetTableReference("table");
var tableQuery = new TableQuery<UserEntity>();
TableContinuationToken continuationToken = null;
do
{
    var query = await table.ExecuteQuerySegmentedAsync(
        tableQuery, continuationToken).ConfigureAwait(false);
    list.AddRange(query.Results);
    continuationToken = query.ContinuationToken;
} while (continuationToken != null);