Booley
Booley

Reputation: 859

Azure Tables: Get all row keys + specific column from entire table?

I have entities stored in one table that look like (truncated here):

public class Record : TableEntity
{
    public double Version;
    public string User;
}

Basically, I want to retrieve all the RowKeys and only the Version column of the entire table (i.e. the entire first 2 columns). There is only one PartitionKey since there aren't too many entries. How can I programmatically retrieve these columns? I'm aware of query projection and have seen the example on the Azure site, but I don't know how to extend it for my purpose here.

Any help would be appreciated!

Upvotes: 1

Views: 5125

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136296

Please try the following code. Essentially you would need to specify the columns you wish to fetch in SelectColumns property of your query. I have not specified any filter criteria because you mentioned that the table doesn't contain that many entities.

    static void QueryProjectionExample()
    {
        var cred = CloudStorageAccount.DevelopmentStorageAccount;
        var client = cred.CreateCloudTableClient();
        var table = client.GetTableReference("TableName");
        var query = new TableQuery<DynamicTableEntity>()
        {
            SelectColumns = new List<string>()
            {
                "RowKey", "Version"
            }
        };
        var queryOutput = table.ExecuteQuerySegmented<DynamicTableEntity>(query, null);

        var results = queryOutput.Results;
        foreach (var entity in results)
        {
            Console.WriteLine("RowKey = " + entity.RowKey + "; Version = " + entity.Properties["Version"].StringValue);
        }
    }

Upvotes: 1

Related Questions