ZeroAlloc.ORM.Generator 2.4.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ZeroAlloc.ORM.Generator --version 2.4.0
                    
NuGet\Install-Package ZeroAlloc.ORM.Generator -Version 2.4.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="ZeroAlloc.ORM.Generator" Version="2.4.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ZeroAlloc.ORM.Generator" Version="2.4.0" />
                    
Directory.Packages.props
<PackageReference Include="ZeroAlloc.ORM.Generator">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
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 ZeroAlloc.ORM.Generator --version 2.4.0
                    
#r "nuget: ZeroAlloc.ORM.Generator, 2.4.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 ZeroAlloc.ORM.Generator@2.4.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=ZeroAlloc.ORM.Generator&version=2.4.0
                    
Install as a Cake Addin
#tool nuget:?package=ZeroAlloc.ORM.Generator&version=2.4.0
                    
Install as a Cake Tool

ZeroAlloc.ORM

NuGet Build codecov License: MIT AOT GitHub Sponsors

Source-generated raw-SQL data access for .NET: you write the SQL, the generator writes the ADO.NET, with no runtime reflection and NativeAOT-ready.

Why ZeroAlloc.ORM

  • Close to hand-written ADO.NET. A 1,000-row read allocates 88,592 B, 0.4% more than hand-written ADO.NET's 88,200 B, where Dapper.AOT allocates 130,000 B in the same run.
  • Ahead of Dapper.AOT on most SQLite workloads. A single-row read takes 1.10× the time of hand-written ADO.NET; Dapper.AOT takes 1.26× in the same run.
  • Works under NativeAOT and trimming. CI publishes and runs AOT consumers on every PR, including ones that share the build with other source generators, where EF Core's precompiled queries collide.
  • Compile-time diagnostics instead of runtime surprises. A non-partial method, a tuple that does not match the SQL's statement count or a parameter with no binding is a build error, ZAO001 to ZAO082.

Install

dotnet add package ZeroAlloc.ORM
dotnet add package ZeroAlloc.ORM.Generator

Then add your ADO.NET provider, such as Microsoft.Data.Sqlite, Npgsql or Microsoft.Data.SqlClient.

Quick start

using Microsoft.Data.Sqlite;
using System.Data.Async;
using System.Data.Async.Adapters;
using ZeroAlloc.ORM;

await using var db = new SqliteConnection("Data Source=:memory:").AsAsync();
await db.OpenAsync();

var customers = new CustomerRepository(db);
await customers.CreateTableAsync();
int id = await customers.AddAsync("Ada");
Console.WriteLine(await customers.FindAsync(id)); // Customer { Id = 1, Name = Ada }

public sealed record Customer(int Id, string Name);

public sealed partial class CustomerRepository(IAsyncDbConnection connection)
{
    [Command("CREATE TABLE Customers (Id INTEGER PRIMARY KEY, Name TEXT NOT NULL)")]
    public partial Task<int> CreateTableAsync(CancellationToken ct = default);

    [Command("INSERT INTO Customers (Name) VALUES (@name) RETURNING Id", Kind = CommandKind.Identity)]
    public partial Task<int> AddAsync(string name, CancellationToken ct = default);

    [Query("SELECT Id, Name FROM Customers WHERE Id = @id")]
    public partial Task<Customer?> FindAsync(int id, CancellationToken ct = default);
}

The generator fills in each partial method with typed parameter binding and row materialization against AdoNet.Async's IAsyncDbConnection. There is no LINQ provider, no expression compilation and no runtime reflection.

What you get

  • Every common result shape: scalars, single rows, lists, IAsyncEnumerable<T> streams and multi-result-set tuples such as (Order Head, IReadOnlyList<OrderLine> Lines).
  • Commands: rows affected, scalars, inserted identities and chunked multi-row bulk inserts.
  • Stored procedures with output, input-output and return-value parameters.
  • Rich types: enums as integers or names, value objects, multi-column composites such as Money, and custom row factories.
  • Transactions by declaring an IAsyncDbTransaction parameter.
  • Provider-aware checks for SQLite, PostgreSQL, SQL Server and MySQL.
  • Migrations: MigrationRunner applies embedded .sql files, with locking for safe concurrent startup on PostgreSQL and SQL Server.
  • Observability through ZeroAlloc.Telemetry's [Instrument]; see the observability recipe.

Every shape, option and diagnostic is in the reference.

Performance

SQLite, BenchmarkDotNet, captured at 2.3.1. Time is the same-run ratio against hand-written ADO.NET; allocations are exact bytes per call.

Workload ZA.ORM time Dapper.AOT time ZA.ORM alloc Dapper.AOT alloc Hand-written alloc
Single-row read 1.10× 1.26× 1,568 B 1,800 B 1,232 B
1,000-row read 0.99× 0.90× 88,592 B 130,000 B 88,200 B
Head + 10 lines 1.04× 1.24× 3,400 B 4,072 B 2,680 B

Full tables, the insert workload, PostgreSQL and methodology: SQLite and PostgreSQL.

Learn more

License

MIT. See LICENSE.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

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
3.0.1 636 11/22/2026
3.0.0 276 11/22/2026
2.17.2 1,019 11/23/2026
2.16.1 10,006 11/11/2026
2.16.0 421 11/10/2026
2.15.0 279 11/10/2026
2.14.0 1,493 11/6/2026
2.13.0 1,330 10/31/2026
2.12.0 274 10/30/2026
2.11.2 165 10/30/2026
2.11.1 103 10/30/2026
2.11.0 247 10/30/2026
2.10.2 690 10/29/2026
2.10.0 1,160 10/23/2026
2.9.0 172 10/23/2026
2.8.0 350 10/22/2026
2.7.0 159 10/22/2026
2.6.0 160 10/22/2026
2.5.0 337 10/21/2026
2.4.0 856 10/18/2026
Loading failed