获取Azure表行数

编程入门 行业动态 更新时间:2024-10-23 20:24:46
本文介绍了获取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表行数

本文发布于:2023-10-19 14:50:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1507845.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:行数   Azure

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!