TableStorage.Abstracts 1.3.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package TableStorage.Abstracts --version 1.3.0
NuGet\Install-Package TableStorage.Abstracts -Version 1.3.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TableStorage.Abstracts" Version="1.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TableStorage.Abstracts --version 1.3.0
#r "nuget: TableStorage.Abstracts, 1.3.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TableStorage.Abstracts as a Cake Addin
#addin nuget:?package=TableStorage.Abstracts&version=1.3.0

// Install TableStorage.Abstracts as a Cake Tool
#tool nuget:?package=TableStorage.Abstracts&version=1.3.0

TableStorage.Abstracts

Azure Table Storage Abstracts library defines abstract base classes for repository pattern.

Build status

NuGet Version

Coverage Status

Download

The TableStorage.Abstracts library is available on nuget.org via package name TableStorage.Abstracts.

To install TableStorage.Abstracts, run the following command in the Package Manager Console

Install-Package TableStorage.Abstracts

More information about NuGet package available at https://nuget.org/packages/TableStorage.Abstracts

Features

  • find one, many and by paged results
  • create, update and delete pattern
  • batch processing for bulk insert/update
  • table initialization on first use

Usage

Dependency Injection

Register services with the Azure storage connection string named 'AzureStorage' loaded from configuration

services.AddTableStorageRepository("AzureStorage");

Example appsettings.json file

{
  "AzureStorage": "UseDevelopmentStorage=true"
}

Register with the Azure storage connection string passed in

services.AddTableStorageRepository("UseDevelopmentStorage=true");

Resolve ITableRepository<T>

var repository = serviceProvider.GetRequiredService<ITableRepository<Item>>();

Resolve TableServiceClient

var tableServiceClient = serviceProvider.GetRequiredService<TableServiceClient>();

Custom Repository

Create a custom repository instance by inheriting TableRepository<T>

public class UserRepository : TableRepository<User>
{
    public UserRepository(ILoggerFactory logFactory, TableServiceClient tableServiceClient)
        : base(logFactory, tableServiceClient)
    { }

    protected override void BeforeSave(User entity)
    {
        // use email as partition key
        entity.PartitionKey = entity.Email;

        base.BeforeSave(entity);
    }

    // uses typeof(TEntity).Name by default, override with custom table name
    protected override string GetTableName() => "UserMembership";
}

Query Operations

Find an entity by row and partition key. Note, table storage requires both.

var repository = serviceProvider.GetRequiredService<ITableRepository<Item>>();
var readResult = await repository.FindAsync(rowKey, partitionKey);

Find all by filter expression

var queryResults = await repository.FindAllAsync(r => r.IsActive);

Find all by filter expression

var itemResult = await repository.FindOneAsync(r => r.Name == itemName);

Find a page of items by filter. Note, Azure Table storage only supports forward paging by Continuation Token.

var pageResult = await repository.FindPageAsync(
    filter: r => r.IsActive,
    pageSize: 20);

// loop through pages
while (!string.IsNullOrEmpty(pageResult.ContinuationToken))
{
    // get next paging using previous continuation token
    pageResult = await repository.FindPageAsync(
        filter: r => r.IsActive,
        continuationToken: pageResult.ContinuationToken,
        pageSize: 20);
}

Update Operations

Create an item

 var createdItem = await repository.CreateAsync(item);

Update an item

 var updatedItem = await repository.UpdateAsync(item);

Save or Upsert an item

 var savedItem = await repository.SaveAsync(item);
RowKey and PartitionKey

Azure Table Storage requires both a RowKey and PartitionKey

The base repository will set the RowKey if it hasn't already been set using the NewRowKey() method. The default implementation is Ulid.NewUlid().ToString()

If PartitionKey hasn't been set, RowKey will be used.

Batch Operations

Bulk insert data

await repository.BatchAsync(items);

Batch Merge data

await repository.BatchAsync(items, TableTransactionActionType.UpdateMerge);
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.4.0 56 5/10/2024
1.3.0 120 4/26/2024
1.2.0 90 4/26/2024
1.1.0 102 4/10/2024
1.0.0 87 4/9/2024