Skip to content

Repository files navigation

Gobie74.AzureStorage

The purpose of this library was to make storing data in Azure Table Storage just a bit easier. Making this available as a package on Nuget.org because I was getting tired of copying the source around and wanted to try out some build pipelines and other tech.

Using

The data types that this library stores must be derived from Microsoft.Azure.Cosmos.Table.ITableEntity.

Construction

Once you have a class you want to store, create a TableAccess<T> object. Currently the constructor takes a connection string, a table name, and optionally a logger interface.

The connection string can be found in the Azure Portal or in Azure Storage Explorer, and possibly other places.

The table name is any non-empty string you want.

The logger interface is a Microsoft.Extensions.Logging.Abstractions logger with the category of TableAccess<T> and is optional.

Example

Using dependency injection during ConfigureServices might look something like this:

services.AddTransient<ITableAccess<Thing>,TableAccess<Thing>>((ctx)=>{varlogger=ctx.GetService<ILogger<TableAccess<Thing>>>();returnnewTableAccess<Thing>(connection,"test",logger);});

Adding Data

Add data to the table by using the AddAsync method.

Example

ThingaThing=newThing{PartitionKey="things",RowKey="1",Name="Hello"};awaittableAccess.AddAsync(aThing);

Updating Data

Update an entity's properties and then call the InsertOrReplaceAsync method.

Example

aThing.Name="Hello World";awaittableAccess.InsertOrReplaceAsync(aThing);

Deleting Data

To delete an entity from the table, call the DeleteAsync method.

Example

awaittableAccess.DeleteAsync(readThing);

Query Data

Currently the library supports querying data by the PartitionKey and RowKey only. Query by property is in development.

To Query for an entity, supply the partition key and row key to the GetSingleAsync method.

Example

varreadThing=awaittableAccess.GetSingleAsync("things","1");

Status

Build status

gobie74.azurestorage package in packageSource feed in Azure Artifacts

nuget

About

Azure storage helper library

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages