Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Azure by (45.3k points)

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.

1 Answer

0 votes
by (16.8k points)
edited by

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

var acc = new CloudStorageAccount(

                         new StorageCredentials("account name", "account key"), true);

var tableClient = acc.CreateCloudTableClient();

var table = tableClient.GetTableReference("table name");

var entities = table.ExecuteQuery(new TableQuery<MyEntity>()).ToList();

However, please keep in mind that table service returns a maximum of 1000 entities in a single call to it. If they're more than 1000 entities available in your table, it returns a continuation token which can be used to fetch the 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.

Are you interested in learning Azure from basics! Here's the right video for you on Azure provided by Intellipaat:

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"), true);

var tableClient = acc.CreateCloudTableClient();

var table = tableClient.GetTableReference("table name");

TableContinuationToken token = null;

var entities = new List<MyEntity>();

do

{

    var queryResult = table.ExecuteQuerySegmented(new TableQuery<MyEntity>(), token);

    entities.AddRange(queryResult.Results);

    token = queryResult.ContinuationToken;

} while (token != null);

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...