Azure Storage abstractions, based on K. Scott Allen ideas and extended to support Tables, Queues and Blobs.
All methods are async only!
The Table Storage entity is declared as a normal TableEntity, e.g.
public class FooEntity : TableEntity
{
public string Bar { get; set; }
public int Baz { get; set; }
}
Define your Table Storage:
public class FooEntityStorage : TableStorage<FooEntity>
{
public FooEntityStorage(string tableName = null, string connectionString = null, StorageInitializeManager storageInitializeManager = null)
: base(tableName, connectionString, storageInitializeManager)
{
}
}
Interface'ify the storage for Dependency Injection:
public interface IFooEntityStorage : ITableStorage<FooEntity>
{
}
public class FooEntityStorage : TableStorage<FooEntity>, IFooEntotyStorage
{
...
}
Remember! Querying in Azure Table Storage where not including PartitionKey (and possibly RowKey) has a huge performance impact. For optimal performance queries should include in descending order of performance impact (see MSDN:
- PartitionKey (exact) + RowKey (exact)
- PartitionKey (exact) + RowKey (partial) + properties
- PartitionKey (partial) + RowKey (partial) + properties
- Everything else
Querying is done by subclassing StorageQuery
public class ListFooEntityByBarStorageQuery: StorageQuery<FooEntity>
{
public ListFooEntityByBarStorageQuery(string bar)
{
Query = Query.Where(
TableQuery.GenerateFilterCondition("Bar", QueryComparisons.Equal, bar));
}
}
Extend the FooEntityStorage class with the List (async) method.
public class FooEntityStorage : TableStorage<FooEntity>
{
...
public async Task<IEnumerable<FooEntity>> ListAsync(string bar)
{
return await new ListFooEntityByBarStorageQuery(bar).ExecuteOnAsync(Table);
}
}
The following queries are implemented by default:
- ListPartitionStorageQuery - list entities in a single partition (see TableStorage.ListAsync())
- ListRowsStorageQuery - list entities by row key (significant performance impact, see TableStorage.ListByRowKeyAsync())
- MultipleEntityStorageQuery - get multiple entities by PartitionKey and RowKey (using TableEntityKey class, see TableStorage.GetAsync() overload)
- MultiplePartitionStorageQuery - list entities in multiple partitions (performance impact)
- MultipleRowKeysStorageQuery - list entities with multiple RowKeys (significant performance impact)
- DateRangeStorageQuery - list entities with having a specific property within a date/time range
By default the MultiplePartitionStorageQuery, MultipleRowKeysStorageQuery and DateRangeStorageQuery queries are not exposed on the TableStorage class because of the significant performance impact (although this also applies to ListRowsStorageQuery).