How to get the Azure table Row count?

0 votes

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

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?

Sep 25, 2018 in Azure by cloudie_crank
• 1,610 points
935 views

1 answer to this question.

0 votes

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.

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 Timestampin 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"});
answered Sep 25, 2018 by null_void
• 3,220 points

Related Questions In Azure

0 votes
1 answer

How to get the list of names of Azure blob files in a container?

We can get some additional info like Size, ...READ MORE

answered Jun 27, 2018 in Azure by club_seesharp
• 3,450 points
1,615 views
0 votes
2 answers

How can I download a .vhd image to my local machine from azure and upload the same to a different azure account?

From the Windows Azure Portal you can ...READ MORE

answered Aug 20, 2018 in Azure by Priyaj
• 56,900 points
3,078 views
0 votes
1 answer

How to calculate the used database space in SQL Azure?

I don't think its possible to find ...READ MORE

answered Mar 5 in Azure by Archana
• 5,560 points
34 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to handle payload formats for both iOS and Android through the Azure Notification Hub?

I think your solution is feasible and ...READ MORE

answered Jul 8 in Azure by Perry
• 17,020 points
95 views
+1 vote
4 answers

How do Connect to Azure website via FTP?

First set up your FTP credentials are ...READ MORE

answered Oct 23, 2018 in Azure by abc
346 views
+1 vote
2 answers

How do I establish an connection to Azure IoT Hub? Say a connection like MQTT/AMQP using Python.

Azure IoT Hub comes with 3 SDK's: Service SDK Device ...READ MORE

answered Apr 13, 2018 in Azure by null_void
• 3,220 points
617 views
0 votes
1 answer

How to determine the number of messages in an Azure Services Bus Queue?

You will get error when you try ...READ MORE

answered Jun 12, 2018 in Azure by null_void
• 3,220 points
290 views
0 votes
1 answer

How to get blob-URL after file upload in azure?

Assuming you're uploading the blobs into blob ...READ MORE

answered Sep 27, 2018 in Azure by null_void
• 3,220 points
2,164 views