获取Azure表行数 [英] Get the Azure table Row count

查看:89
本文介绍了获取Azure表行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Azure表存储的新手.我想获取表中的总行数.

I am new to Azure table storage. I want to get the total row count in a table.

目前Iam正在做这样的事情:-

Currently Iam doing something like this:-

public List<T> ReadAll(string partitionKey)
    {
        List<T> entities = new List<T>();

        TableQuery<T> query = new TableQuery<T>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey.ToLower()));
        entities = Table.ExecuteQuery(query).ToList();

        return entities;
    }

这当前会读取所有表条目.涉及较少的记录时,这可以正常工作.但是我担心什么时候记录会增加,这种方法会很乏味.

This currently reads through all the table entries. This works ok when it comes to less records. But I am concerned when the records would increase and this method would be tedious.

还有其他优雅的方法吗?

Is there any other elegant way to do it?

推荐答案

不幸的是,没有其他方法可以做到这一点.您可能要做的一件事就是仅使用查询投影仅获取少量属性.这样做是为了减少响应有效负载,从而在某种程度上加快操作速度.

Unfortunately there's no other way to do this. One thing you could possibly do is just fetch only few attributes only using query projection. What this will do is reduce the response payload and thus speed up the operation somewhat.

为了详细说明我的答案,到目前为止,获取实体总数的唯一方法是获取所有实体.上面的代码获取实体不需要的所有属性,因为您只对获取实体计数感兴趣.这就是为什么我说您仅获取PartitionKey, RowKey, and Timestamp属性的原因.要仅获取属性的子集,可以使用query projection并指定要获取的属性列表(在我们的示例中为PartitionKey, RowKey, and Timestamp).为此,只需将查询修改为:

To elaborate my answer, as of today the only way to get the total count of entities is by fetching all entities. Your code above fetches all attributes for entities which is not really required because you're only interested in getting count of entities. That's why I said that you only fetch PartitionKey, RowKey, and Timestamp attributes only. To fetch only a subset of attributes, you could use query projection and specify a list of attributes you want to fetch (PartitionKey, RowKey, and Timestamp in our example). To do so, just modify your query to something like:

TableQuery<T> query = new TableQuery<T>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey.ToLower())).Select(new List<string> {"PartitionKey", "RowKey", "Timestamp"});

这篇关于获取Azure表行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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