Using this code block
try
{
StorageCredentials creds = new StorageCredentials(accountName, accountKey);
CloudStorageAccount account = new CloudStorageAccount(creds, useHttps: true);
CloudTableClient client = account.CreateCloudTableClient();
CloudTable table = client.GetTableReference("serviceAlerts");
TableOperation retrieveOperation = TableOperation.Retrieve<ServiceAlertsEntity>("ServiceAlerts", "b9ccd839-dd99-4358-b90f-46781b87f933");
TableResult query = table.Execute(retrieveOperation);
if (query.Result != null)
{
outline = outline + ((ServiceAlertsEntity) query.Result).alertMessage + " * ";
}
else
{
Console.WriteLine("No Alerts");
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
I am able to retrieve the single record with the partition and rowkey mentioned in the retrieve.
Is there a way I can get all the records that are stored in the partition of ServiceAlerts?
I have tried a wildcard (*) for the second parameter
TableOperation retrieveOperation = TableOperation.Retrieve<ServiceAlertsEntity>(
"ServiceAlerts","b9ccd839-dd99-4358-b90f-46781b87f933");
but it does not return anything.
Enter an Account Name, Account Key, and Table Name on the Azure Table tab of the New Session dialog. Select either HTTP or HTTPS as the connection Protocol. Ensure that the Analysis Grid viewer is selected in the Start With drop-down list. Start retrieving data by clicking the Start button in the New Session dialog.
You can use Azure Storage Explorer. It is free and supported by Microsoft. Browse to the appropriate storage account, click on the table storage you want to export and look for the export option in the explorer. As at 2020, this should be the accepted answer.
You need to specify a TableQuery, this will give you all entities or you can specify a TableQuery.GenerateFilterCondition
to filter the rows.
TableQuery<ServiceAlertsEntity> query = new TableQuery<ServiceAlertsEntity>();
foreach (ServiceAlertsEntity entity in table.ExecuteQuery(query))
{
Console.WriteLine("{0}, {1}\t{2}\t{3}", entity.PartitionKey, entity.RowKey,
entity.Field1, entity.Field2);
}
If you need further control over the records being returned, you can use ExecuteQuerySegmentedAsync
to retrieve data a page (around 1,000 records) at a time.
var alerts = new List<ServiceAlertsEntity>();
var query = new TableQuery<ServiceAlertsEntity>();
TableContinuationToken continuationToken = null;
do
{
var page = await table.ExecuteQuerySegmentedAsync(query, continuationToken);
continuationToken = page.ContinuationToken;
alerts.AddRange(page.Results);
}
while (continuationToken != null);
Or if you need to restrict your results, e.g. by Partition Key, you can add a filter condition by adding a Where
clause to the query in the above code.
var pk = "abc";
var filterPk = TableQuery.GenerateFilterCondition(
nameof(ServiceAlertsEntity.PartitionKey),
QueryComparisons.Equal, pk);
var query = new TableQuery<ServiceAlertsEntity>().Where(filterPk);
MS Azure reference
You're using wrong class. Use TableQuery to retrieve multiple results. https://msdn.microsoft.com/en-us/library/azure/microsoft.windowsazure.storage.table.tablequery.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With