如何查询在Windows Azure的表存储的所有行? [英] How to query all rows in windows azure table storage?

查看:269
本文介绍了如何查询在Windows Azure的表存储的所有行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的天蓝色表格内的所有实体的名单。任何想法,我将如何去写这个查询?我使用C#顺便说一句。谢谢你。

I am trying to get a list of all entities inside my azure table. Any idea how I would go about writing this query? I am using c# btw. Thanks.

推荐答案

要回答你的问题,你可以做类似如下:

To answer your question, you could do something like the following:

var acc = new CloudStorageAccount(
                         new StorageCredentials("account name", "account key"), false);
var tableClient = acc.CreateCloudTableClient();
var table = tableClient.GetTableReference("table name");
var entities = table.ExecuteQuery(new TableQuery()).ToList();

但是,请记住,表服务于一个单一的呼叫最多1000个实体返回。如果是在表中提供超过1000个实体,它返回一个延续标记可用于获取下一组实体。在的executeQuery 方法实际上处理这种延续标记内部因此,如果要取消这个操作因任何原因,你不能做到这一点。

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.

有一个更好的办法是使用 ExecuteQuerySegmented 方法,并让应用程序处理的标记。这里的样本code这样做的:

A better approach would be to use ExecuteQuerySegmented method and have your application deal with the token. Here's the sample code to do so:

var acc = new CloudStorageAccount(
                         new StorageCredentials("account name", "account key"), false);
var tableClient = acc.CreateCloudTableClient();
var table = tableClient.GetTableReference("table name");
TableContinuationToken token = null;
var entities = new List<DynamicTableEntity>();
do
{
    var queryResult = table.ExecuteQuerySegmented(new TableQuery(), token);
    entities.AddRange(queryResult.Results);
    token = queryResult.ContinuationToken;
} while (token != null);

这篇关于如何查询在Windows Azure的表存储的所有行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆