Get Counter Azure Table

I am new to Azure table storage. I want to get the total number of rows in a table.

I am currently 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;
    }

He is currently reading all the entries in the table. This works fine when it comes to fewer entries. But it bothers me when the records will increase, and this method will be tedious.

Is there any other elegant way to do this?

+4
source share
2 answers

, . , , - . , .

, . , , . , PartitionKey, RowKey, and Timestamp. , query projection , (PartitionKey, RowKey, and Timestamp ). - :

TableQuery<T> query = new TableQuery<T>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey.ToLower())).Select(new List<string> {"PartitionKey", "RowKey", "Timestamp"});
+13

, #, , Powershell. Azure Powershell.

, PartitionKey, RowKey, Timestamp ETag, , . SelectColumns , , .

function GetTable($connectionString, $tableName)
{
    $context = New-AzureStorageContext -ConnectionString $connectionString
    $azureStorageTable = Get-AzureStorageTable $tableName -Context $context
    $azureStorageTable
}

function GetTableCount($table)
{
    #Create a table query.
    $query = New-Object Microsoft.WindowsAzure.Storage.Table.TableQuery

    #Define columns to select. 
    $list = New-Object System.Collections.Generic.List[string] 
    $list.Add("PartitionKey")

    #Set query details.
    $query.SelectColumns = $list

    #Execute the query.
    $entities = $table.CloudTable.ExecuteQuery($query)
    ($entities | measure).Count
}

$connectionString = "<yourConnectionString>"
$table = GetTable $connectionString <yourTableName>
GetTableCount $table

, -!

+5

All Articles