Sparcpoint.Extensions.Azure 1.6.15

dotnet add package Sparcpoint.Extensions.Azure --version 1.6.15
NuGet\Install-Package Sparcpoint.Extensions.Azure -Version 1.6.15
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="Sparcpoint.Extensions.Azure" Version="1.6.15" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sparcpoint.Extensions.Azure --version 1.6.15
#r "nuget: Sparcpoint.Extensions.Azure, 1.6.15"
#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 Sparcpoint.Extensions.Azure as a Cake Addin
#addin nuget:?package=Sparcpoint.Extensions.Azure&version=1.6.15

// Install Sparcpoint.Extensions.Azure as a Cake Tool
#tool nuget:?package=Sparcpoint.Extensions.Azure&version=1.6.15

Sparcpoint.Extensions.Azure

[TODO]

Installation

Package Manager Console

Install-Package Sparcpoint.Extensions.Azure

.NET Core CLI

dotnet add package Sparcpoint.Extensions.Azure

Usage

Table Storage

The table storage extensions allow for easy saving and loading from table storage using the JsonTableEntity. JsonTableEntity itself is NOT an ITableEntity but if used with the appropriate extensions included, allows for quick upserting. Additional features are included as well, utilizing attributes to define PartitionKey / RowKey formats.

First, you must inherit from JsonTableEntity and add whatever properties you would like to the entity. All basic types will use native table storage types while complex types will be serialized into JSON and stored in a string type.

Optionally, you can add a TableKeyAttribute to specify how the PartitionKey and RowKey are formed. These use properties names to form the resulting keys. Otherwise, you must specify PartitionKey and RowKey on the object manually.

[TableKey(":subscriptions", "{SubscriptionName}")]
public class SubscriptionEntity : JsonTableEntity
{
  public string SubscriptionName { get; set; }
  public PaymentDetails PaymentMethod { get; set; }
  public DateTime CreatedTimestamp { get; set; } = DateTime.UtcNow;
}

public class PaymentDetails
{
  public string Name { get; set; }
  public string CardNumber { get; set; }
  public int CardExpirationYear { get; set; }
  public int CardExpirationMonth { get; set; }
  public string SecurityCode { get; set; }
}

In order to save this to a table you need a TableClient. Then use the UpsertEntityAsync<T> extension provided.

public void Main(string[] args)
{
  string connectionString = "<your connection string>";
  string tableName = "<your table name>";

  var client = new TableClient(connectionString, tableName);
  var response = await client.UpsertEntityAsync(new SubscriptionEntity 
  {
    SubscriptionName = "Default",
    PaymentMethod = new PaymentDetails
    {
      Name = "John Smith",
      CardNumber = "1111000011110000",
      CardExpirationYear = 2025,
      CardExpirationMonth = 12,
      SecurityCode = 100
    }
  });
}

And that is all that is needed to insert / update your entity. The result will be a table with the following values:

Column Value
PartitionKey ":subscriptions"
RowKey "Default"
SubscriptionName "Default"
PaymentMethod "{"name":"John Smith","cardNumber":"1111000011110000","cardExpirationYear":2025,"cardExpirationMonth":12,"securityCode":100}"
CreatedTimestamp 2024-04-23T23:10:03Z
Timestamp 2024-04-23T23:10:03Z
ETag [Generated Value]
Extension Methods

Insert / Update an Entity Task<Azure.Response> UpsertEntityAsync<T>(this TableClient client, T entity, TableUpdateMode updateMode = TableUpdateMode.Merge, CancellationToken cancelToken = default) where T : JsonTableEntity

Update an Entity Only (must exist) Task<Azure.Response> UpdateEntityAsync<T>(this TableClient client, T entity, ETag etag, TableUpdateMode updateMode = TableUpdateMode.Merge, CancellationToken cancelToken = default) where T : JsonTableEntity

Insert an Entity Only (cannot exist) Task<Azure.Response> AddEntityAsync<T>(this TableClient client, T entity, CancellationToken cancelToken = default) where T : JsonTableEntity

Query using a standard table query filter MSDN / Storage Services / Querying tables and entities

IAsyncEnumerable<T> QueryAsync<T>(this TableClient client, string filter, int? maxPerPage = null, IEnumerable<string>? select = null, [EnumeratorCancellation] CancellationToken cancelToken = default) where T : JsonTableEntity, new()

Perform a partition query based on TableKeyAttribute The parameters object is used to format the PartitionKey property of the TableKeyAttribute of T. So if the partition key format is :groups:{GroupName}, then the parameters object should have a GroupName property included.

IAsyncEnumerable<T> PartitionQueryAsync<T>(this TableClient client, object? parameters = null, int? maxPerPage = null, IEnumerable<string>? select = null, CancellationToken cancelToken = default) where T : JsonTableEntity, new()

Perform a partition query based on a string value IAsyncEnumerable<T> PartitionQueryAsync<T>(this TableClient client, string partitionKey, int? maxPerPage = null, IEnumerable<string>? select = null, CancellationToken cancelToken = default) where T : JsonTableEntity, new()

Retrieve an entity, if it exists, based on TableKeyAttribute The parameters object is used to format the PartitionKey property and the RowKey property of the TableKeyAttribute of T. So if the partition key format is :subscriptions:{SubscriptionName} and the row key format is :users:{UserName} then the parameters object should have both a SubscriptionName property and UserName property.

Task<T?> GetEntityIfExistsAsync<T>(this TableClient client, object? parameters = null, IEnumerable<string>? select = null, CancellationToken cancelToken = default) where T : JsonTableEntity, new()

Retrieve an entity, if it exists, based on string values Task<T?> GetEntityIfExistsAsync<T>(this TableClient client, string partitionKey, string rowKey, IEnumerable<string>? select = null, CancellationToken cancelToken = default) where T : JsonTableEntity, new()

Retrieve an entity, based on TableKeyAttribute The parameters object is used to format the PartitionKey property and the RowKey property of the TableKeyAttribute of T. So if the partition key format is :subscriptions:{SubscriptionName} and the row key format is :users:{UserName} then the parameters object should have both a SubscriptionName property and UserName property.

Task<T> GetEntityAsync<T>(this TableClient client, object? parameters = null, IEnumerable<string>? select = null, CancellationToken cancelToken = default) where T : JsonTableEntity, new()

Retrieve an entity, based on string values Task<T> GetEntityAsync<T>(this TableClient client, string partitionKey, string rowKey, IEnumerable<string>? select = null, CancellationToken cancelToken = default) where T : JsonTableEntity, new()

Bulk add entities Task BulkAddAsync<T>(this TableClient client, IEnumerable<T> items, int chunkSize = 25, CancellationToken cancelToken = default) where T : JsonTableEntity

Bulk Insert / Update Entities (Replace) Task BulkUpsertReplaceAsync<T>(this TableClient client, IEnumerable<T> items, int chunkSize = 25, CancellationToken cancelToken = default) where T : JsonTableEntity

Bulk Insert / Update Entities (Merge Properties) Task BulkUpsertMergeAsync<T>(this TableClient client, IEnumerable<T> items, int chunkSize = 25, CancellationToken cancelToken = default) where T : JsonTableEntity

Examples

[TODO]

Product Compatible and additional computed target framework versions.
.NET 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. 
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.6.15 40 5/19/2024
1.6.14 39 5/19/2024
1.6.13 49 5/17/2024
1.6.12 37 5/17/2024
1.6.11 49 5/16/2024
1.6.10 48 5/16/2024
1.6.9 48 5/16/2024
1.6.8 48 5/16/2024
1.6.7 60 5/16/2024
1.6.6 76 5/15/2024
1.6.5 85 5/12/2024
1.6.4 112 4/30/2024
1.6.3 90 4/27/2024
1.6.2 83 4/22/2024
1.6.1 85 4/22/2024
1.6.0 87 4/21/2024
1.5.3 88 4/19/2024
1.5.2 77 4/18/2024
1.5.0 83 4/17/2024
1.4.0 77 4/3/2024

Permissions