Microsoft.Orleans.Persistence.AdoNet 9.2.0-preview2

Prefix Reserved
This is a prerelease version of Microsoft.Orleans.Persistence.AdoNet.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Microsoft.Orleans.Persistence.AdoNet --version 9.2.0-preview2
                    
NuGet\Install-Package Microsoft.Orleans.Persistence.AdoNet -Version 9.2.0-preview2
                    
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="Microsoft.Orleans.Persistence.AdoNet" Version="9.2.0-preview2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Microsoft.Orleans.Persistence.AdoNet" Version="9.2.0-preview2" />
                    
Directory.Packages.props
<PackageReference Include="Microsoft.Orleans.Persistence.AdoNet" />
                    
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 Microsoft.Orleans.Persistence.AdoNet --version 9.2.0-preview2
                    
#r "nuget: Microsoft.Orleans.Persistence.AdoNet, 9.2.0-preview2"
                    
#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 Microsoft.Orleans.Persistence.AdoNet@9.2.0-preview2
                    
#: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=Microsoft.Orleans.Persistence.AdoNet&version=9.2.0-preview2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Microsoft.Orleans.Persistence.AdoNet&version=9.2.0-preview2&prerelease
                    
Install as a Cake Tool

Microsoft Orleans Persistence for ADO.NET

Introduction

Microsoft Orleans Persistence for ADO.NET provides grain persistence for Microsoft Orleans using relational databases through ADO.NET. This provider allows your grains to persist their state in various relational databases including SQL Server, MySQL, PostgreSQL, and Oracle.

Getting Started

To use this package, install it via NuGet:

dotnet add package Microsoft.Orleans.Persistence.AdoNet

You will also need to install the appropriate database driver package for your database system:

  • SQL Server: Microsoft.Data.SqlClient or System.Data.SqlClient
  • MySQL: MySql.Data or MySqlConnector
  • PostgreSQL: Npgsql
  • Oracle: Oracle.ManagedDataAccess.Core
  • SQLite: Microsoft.Data.Sqlite

Example - Configuring ADO.NET Persistence

using Microsoft.Extensions.Hosting;
using Orleans.Configuration;
using Orleans.Hosting;

var builder = Host.CreateApplicationBuilder(args)
    .UseOrleans(siloBuilder =>
    {
        siloBuilder
            .UseLocalhostClustering()
            // Configure ADO.NET as grain storage
            .AddAdoNetGrainStorage(
                name: "AdoNetStore", 
                configureOptions: options =>
                {
                    options.Invariant = "System.Data.SqlClient";  // Or other providers like "MySql.Data.MySqlClient", "Npgsql", etc.
                    options.ConnectionString = "Server=localhost;Database=OrleansStorage;User Id=myUsername;******;";
                    // Optional: Configure custom queries
                    options.UseJsonFormat = true; // Store as JSON instead of binary
                });
    });

// Run the host
await builder.RunAsync();

Example - Using Grain Storage in a Grain

using System;
using System.Threading.Tasks;
using Orleans;
using Orleans.Runtime;

// Define grain state class
public class MyGrainState
{
    public string Data { get; set; }
    public int Version { get; set; }
}

// Grain implementation that uses the ADO.NET storage
public class MyGrain : Grain, IMyGrain, IGrainWithStringKey
{
    private readonly IPersistentState<MyGrainState> _state;

    public MyGrain([PersistentState("state", "AdoNetStore")] IPersistentState<MyGrainState> state)
    {
        _state = state;
    }

    public async Task SetData(string data)
    {
        _state.State.Data = data;
        _state.State.Version++;
        await _state.WriteStateAsync();
    }

    public Task<string> GetData()
    {
        return Task.FromResult(_state.State.Data);
    }
}

Database Setup

Before using the ADO.NET provider, you need to set up the necessary database tables. Scripts for different database systems are available in the Orleans source repository:

Documentation

For more comprehensive documentation, please refer to:

Feedback & Contributing

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 was computed.  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 (12)

Showing the top 5 NuGet packages that depend on Microsoft.Orleans.Persistence.AdoNet:

Package Downloads
Microsoft.Orleans.OrleansSqlUtils

Library of utility types for relational storage of Microsoft Orleans

KingMetal.Domains.Abstractions

Package Description

Mtl.Infrastructures.Workers

主要是封装了下Netty服务器和客户端的方法,提供了简单的方法调用就能启动Netty服务器和客户端,封装了Orleans的服务器和客户端的启动和连接方法,使操作简单,减少重复的代码

ZLSoft.QWPlatform.WebBasics

基础服务

Orleans.AdoNet.Extensions

Orleans extensions for configuring cluster,reminder,grain persistence and so on

GitHub repositories (3)

Showing the top 3 popular GitHub repositories that depend on Microsoft.Orleans.Persistence.AdoNet:

Repository Stars
axzxs2001/Asp.NetCoreExperiment
原来所有项目都移动到**OleVersion**目录下进行保留。新的案例装以.net 5.0为主,一部分对以前案例进行升级,一部分将以前的工作经验总结出来,以供大家参考!
OrleansContrib/Orleans.Sagas
A distributed saga implementation for Orleans
shinyorg/templates
dotnet CLI & Visual Studio Templates
Version Downloads Last Updated
9.2.1 7,916 7/16/2025
9.2.0 1,203 7/14/2025
9.2.0-preview3 423 6/10/2025
9.2.0-preview2 208 6/4/2025
9.2.0-preview1 312 4/4/2025
9.1.2 41,729 2/13/2025
9.0.1 23,792 11/23/2024
9.0.0 2,623 11/14/2024
8.2.0 95,139 7/12/2024
8.2.0-preview1 352 5/22/2024
8.1.0 53,741 4/17/2024
8.1.0-preview3 253 3/11/2024
8.1.0-preview2 378 2/23/2024
8.1.0-preview1 180 2/13/2024
8.0.0 52,696 1/5/2024
8.0.0-rc2 284 12/20/2023
8.0.0-rc1 351 12/4/2023
7.2.7 3,303 10/15/2024
7.2.6 16,449 3/9/2024
7.2.5 562 2/22/2024
7.2.4 13,972 12/2/2023
7.2.3 19,915 11/3/2023
7.2.2 7,127 10/16/2023
7.2.1 194,075 7/11/2023
7.2.0 655 7/7/2023
7.1.2 58,952 4/19/2023
7.1.1 8,169 3/23/2023
7.1.0 12,117 2/1/2023
7.0.0 20,865 11/8/2022
7.0.0-rc2 618 10/19/2022
4.0.0-preview2 2,472 8/4/2022
4.0.0-preview1 3,032 2/10/2022
3.8.0 607 5/6/2025
3.8.0-preview5 241 5/12/2025
3.8.0-preview3 226 4/8/2025
3.8.0-preview2 132 4/4/2025
3.8.0-preview1 191 3/31/2025
3.7.2 48,079 5/10/2024
3.7.1 44,700 5/27/2023
3.7.0 8,413 3/23/2023
3.6.5 184,876 8/15/2022
3.6.4 14,168 8/10/2022
3.6.3 7,167 8/4/2022
3.6.2 76,194 4/15/2022
3.6.1 30,202 4/5/2022
3.6.0 83,085 1/20/2022
3.5.1 156,815 11/8/2021
3.5.0 158,426 9/3/2021
3.4.4 1,690 10/4/2021
3.4.3 68,076 6/3/2021
3.4.2 48,182 4/5/2021
3.4.1 192,886 2/3/2021
3.4.0 19,973 1/6/2021
3.4.0-rc1 569 12/9/2020
3.3.0 65,593 9/9/2020
3.3.0-rc2 527 9/2/2020
3.3.0-rc1 534 8/19/2020
3.2.2 17,577 7/22/2020
3.2.1 6,611 7/2/2020
3.2.0 16,126 6/4/2020
3.2.0-rc2 658 5/20/2020
3.2.0-rc1 538 5/7/2020
3.1.7 7,161 5/19/2020
3.1.6 47,563 4/16/2020
3.1.5 2,766 4/9/2020
3.1.4 3,271 3/26/2020
3.1.3 6,916 3/16/2020
3.1.2 13,333 3/5/2020
3.1.0 3,621 2/23/2020
3.1.0-rc3 680 2/13/2020
3.1.0-rc2 627 2/12/2020
3.1.0-rc1 675 2/10/2020
3.0.2 61,320 12/12/2019
3.0.1 17,135 11/27/2019
3.0.0 39,096 10/24/2019
3.0.0-rc2 702 10/16/2019
3.0.0-rc1 584 10/9/2019
3.0.0-beta1 43,542 8/16/2019
2.4.5 118,485 12/29/2019
2.4.4 44,737 11/27/2019
2.4.3 54,413 10/10/2019
2.4.2 23,590 8/31/2019
2.4.1 12,737 8/14/2019
2.4.0 3,117 8/8/2019
2.3.6 11,431 7/24/2019
2.3.5 21,384 6/14/2019
2.3.4 16,488 6/4/2019
2.3.3 3,217 6/2/2019
2.3.2 16,826 5/9/2019
2.3.1 12,727 4/26/2019
2.3.0 49,213 3/20/2019
2.3.0-rc2 3,524 3/13/2019
2.3.0-rc1 2,599 3/4/2019
2.2.4 4,912 2/25/2019
2.2.3 10,092 1/17/2019
2.2.0 11,891 12/13/2018
2.2.0-rc1 2,679 12/4/2018
2.2.0-beta1 3,267 10/21/2018
2.1.2 13,374 10/11/2018
2.1.0 7,895 9/28/2018
2.1.0-rc2 3,198 9/21/2018
2.1.0-rc1 3,352 9/14/2018
2.1.0-beta1 3,251 8/27/2018
2.0.0 15,938 3/28/2018
2.0.0-rc2 3,355 3/13/2018
2.0.0-rc1 3,452 2/26/2018
2.0.0-beta3 4,004 12/21/2017