I am storing tasks in an Azure Table, I would always retrieve them by Id.
public sealed class ProjectTask
{
public required string Id { get; set; }
public string? ParentId { get; set; }
public required string Project { get; set; }
public required string Title { get; set; }
public required string Description { get; set; }
}
I cannot think of any suitable partition key - I do not have multiple task types, nor this will not be a multi-tenant application.
Pointers appreciated.
public async Task<ProjectTask?> GetTaskById(string id, CancellationToken cancellationToken)
{
try
{
var response = await tableClient.GetEntityAsync<TableEntity>("PartitionKey", id, cancellationToken: cancellationToken);
return /* do something */
}
catch (Azure.RequestFailedException ex) when (ex.Status == 404)
{
logger.LogWarning($"Task with ID {id} not found.");
return null;
}
}
I agree with Gaurav Mantri and Adam Vincent.
If you're unsure about a suitable partition key for your Azure Table and your tasks don't have distinct attributes for partitioning, you can opt for a generic approach. This could involve using a constant value as the partition key, evenly distributing data across partitions. While it may not optimize performance, it's effective for smaller applications or when specific partitioning criteria are lacking.
Here's the code with the solution to use a constant value as the partition key:
Output:-