TransactR.EntityFramework 0.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package TransactR.EntityFramework --version 0.2.0
                    
NuGet\Install-Package TransactR.EntityFramework -Version 0.2.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="TransactR.EntityFramework" Version="0.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TransactR.EntityFramework" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="TransactR.EntityFramework" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TransactR.EntityFramework --version 0.2.0
                    
#r "nuget: TransactR.EntityFramework, 0.2.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.
#:package TransactR.EntityFramework@0.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TransactR.EntityFramework&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=TransactR.EntityFramework&version=0.2.0
                    
Install as a Cake Tool

TransactR.EntityFramework

TransactR.EntityFramework is a library that provides an IMementoStore implementation based on Entity Framework Core, allowing you to persist transaction state directly in the application's database. This library integrates cleanly with an existing DbContext, following an approach similar to OpenIddict.

Installation

First, install the NuGet package in your project.

dotnet add package TransactR.EntityFramework

Configuration

Configuration involves two simple steps:

1. Modifying the DbContext

To allow Entity Framework to create the necessary tables for mementos, you need to extend your DbContext and add the entities. A clean way to do this is by using the UseTransactR extension method in your DbContextOptionsBuilder.

public class ApplicationDbContext : DbContext
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
        : base(options) { }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        // Add your model configuration here...
    }
}

Modify the DbContext service configuration in your Program.cs or Startup.cs file to use the UseTransactR extension method:

// Program.cs
builder.Services.AddDbContext<ApplicationDbContext>(options =>
{
    options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"));
    // Add the TransactR entities to your model.
    options.UseTransactR<ApplicationDbContext, MyState, int>();
});

2. Adding Migrations

After configuring your DbContext, run the following commands to create a migration that includes the TransactR tables:

dotnet ef migrations add AddTransactR
dotnet ef database update

This will create the Mementos table in your database.

3. Service Injection

Finally, register the memento store in the Dependency Injection container:

// Program.cs
builder.Services.AddEntityFrameworkMementoStore<ApplicationDbContext, MyState, int>();

Usage Example

After configuration, you can inject IMementoStore<MyState, int> into your services or controllers to save and retrieve mementos.

public class MyService
{
    private readonly IMementoStore<MyState, int> _mementoStore;

    public MyService(IMementoStore<MyState, int> mementoStore)
    {
        _mementoStore = mementoStore;
    }

    public async Task PerformOperationAsync(string transactionId, MyState state)
    {
        // Save a new memento
        await _mementoStore.SaveAsync(transactionId, 1, state);

        // Retrieve a memento
        var retrievedMemento = await _mementoStore.RetrieveAsync(transactionId, 1);
        
        // Remove a memento
        await _mementoStore.RemoveAsync(transactionId, 1);
    }
}

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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
0.2.2 0 9/8/2025
0.2.0 63 9/5/2025
0.1.11 117 9/1/2025
0.1.10 119 9/1/2025
0.1.9 113 9/1/2025
0.1.8 119 9/1/2025