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
8,233 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"});

Hope it helped!

If you need to know more about Azure, then you should join Azure training course online today.

Thank you!!

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
21,899 views
0 votes
1 answer

How to get available ips in the VNet in Azure?

Hi@akhtar, The available ips depend on the network ...READ MORE

answered Nov 12, 2020 in Azure by MD
• 95,460 points
3,282 views
0 votes
1 answer

How to get the azure account tenant Id?

Hi@akhtar, You can find the tenant id with ...READ MORE

answered Dec 21, 2020 in Azure by MD
• 95,460 points

edited Oct 6, 2023 by Khan Sarfaraz 1,402 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
• 58,020 points
14,019 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, 2019 in Azure by Archana
• 5,640 points
1,270 views
0 votes
1 answer

How to add a body to a HttpWebRequest that is being used with the Azure Service management API?

The following code should help: byte[] buf = ...READ MORE

answered Apr 3, 2019 in Azure by Prerna
• 1,960 points
2,718 views
0 votes
1 answer

How to know the Azure backup frequency/retention range associated with Azure Backup Policy?

The following code snippet will provide you ...READ MORE

answered Apr 8, 2019 in Azure by Prerna
• 1,960 points
1,382 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
4,647 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
15,965 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP