如何检索 Azure Table 数据库中的所有实体?

How to retrieve all entities in Azure Table DB?

下面的代码检索所有 PartitionKey = "Smith".

的实体

如果我想消除这个约束和return table中的所有实体,我应该如何修改下面的代码?

对不起,如果这个问题看起来很愚蠢,但我是 C# 和 AzureDBs 的新手,官方网站上的教程和示例代码非常有限。

TableQuery<CustomerEntity> query = new TableQuery<CustomerEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "Smith"));

foreach (CustomerEntity entity in table.ExecuteQuery(query))
{
    Console.WriteLine("{0}, {1}\t{2}\t{3}", entity.PartitionKey, entity.RowKey,
        entity.Email, entity.PhoneNumber);
}

您无法使用 where 属性来过滤您想要的内容。

参考以下代码:TableQuery<CustomerEntity> query = new TableQuery<CustomerEntity>();

这是完整的代码:

static void Main(string[] args)
{
    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
    CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

    CloudTable table = tableClient.GetTableReference("people");
    table.CreateIfNotExists();

    TableQuery<CustomerEntity> query = new TableQuery<CustomerEntity>();
    foreach (CustomerEntity entity in table.ExecuteQuery(query))
    {
        Console.WriteLine("{0}, {1}\t{2}\t{3}", entity.PartitionKey, entity.RowKey,
        entity.Email, entity.PhoneNumber);
    }
}

屏幕截图:

However please keep in mind that table service returns a maximum of 1000 entities in a single call to it. If there're more than 1000 entities available in your table, it returns a continuation token which can be used to fetch next set of entities. The ExecuteQuery method actually handles this continuation token internally thus if you want to cancel this operation for any reason, you can't do that.

您可以像 Gaurav 所说的那样使用 var queryResult = table.ExecuteQuerySegmented(new TableQuery<MyEntity>(), token);

更多细节,你可以参考这个reply