Quarry 0.4.0

dotnet add package Quarry --version 0.4.0
                    
NuGet\Install-Package Quarry -Version 0.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="Quarry" Version="0.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Quarry" Version="0.4.0" />
                    
Directory.Packages.props
<PackageReference Include="Quarry" />
                    
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 Quarry --version 0.4.0
                    
#r "nuget: Quarry, 0.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 Quarry@0.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=Quarry&version=0.4.0
                    
Install as a Cake Addin
#tool nuget:?package=Quarry&version=0.4.0
                    
Install as a Cake Tool

Quarry

Type-safe SQL builder for .NET 10. Source generators + C# 12 interceptors emit all SQL at compile time. AOT compatible. Zero runtime dependencies. Structured logging via Logsmith Abstraction mode.

Documentation | API Reference | Benchmark Dashboard


Packages

Name NuGet Description
Quarry Quarry Runtime types: builders, schema DSL, dialects, executors.
Quarry.Generator Quarry.Generator Roslyn incremental source generator + interceptor emitter.
Quarry.Analyzers Quarry.Analyzers Compile-time SQL query analysis rules (QRA series) with code fixes.
Quarry.Analyzers.CodeFixes Quarry.Analyzers.CodeFixes Code fix providers for QRA diagnostics.
Quarry.Migration Quarry.Migration Cross-ORM conversion toolkit with Roslyn analyzers + code fixes for EF Core, Dapper, ADO.NET, and SqlKata (QRM series). Backs quarry convert.
Quarry.Tool Quarry.Tool CLI tool for migrations, database scaffolding, and cross-ORM conversion (quarry command).

Why Quarry Exists

In most .NET data access libraries, SQL is built at runtime. LINQ expressions are translated on every call, column mapping relies on reflection, and query errors only surface when the code executes. This makes runtime performance harder to predict and rules out scenarios like NativeAOT where reflection is restricted.

Quarry is a compile-time SQL builder — not an ORM. A Roslyn incremental source generator analyzes your C# query expressions at build time and emits pre-built SQL as string literals — no runtime translation, no reflection, no fallback. Queries that can't be statically analyzed produce a compile error, not a runtime surprise.

ORM (EF Core) Compile-time SQL builder (Quarry) Micro-ORM (Dapper)
Schema definition Yes Yes No
SQL authoring Auto (LINQ → SQL at runtime) Auto (C# → SQL at compile time) Manual
Object mapping Reflection-based Source-generated readers Reflection / AOT
Change tracking Yes No No
Migrations Yes Yes No

Comparison with Other Approaches

Capability Quarry EF Core Dapper SqlKata
SQL generated at compile time Yes No (runtime LINQ translation) No (hand-written SQL) No (runtime builder)
Reflection-free Yes No Partial (AOT mode) No
Zero-allocation query dispatch Yes (carrier architecture) No No No
NativeAOT compatible Yes Partial Partial No
Compile-time diagnostics Yes Limited No No
Compile-time constant inlining Yes No N/A No
No runtime dependencies Yes No Yes Yes
Type-safe schema definition Yes Yes (DbContext/model) No No
Multi-dialect support Yes (4 dialects) Yes (providers) Manual Yes
Join support Up to 6 tables Unlimited Manual Yes
Navigation joins (One<T>, HasManyThrough) Yes (compile-time) Yes (conventions) No No
Navigation subqueries Yes (Any/All/Count/Sum/Min/Max/Avg) Yes (full LINQ) No No
Window functions Yes (compile-time) Limited Manual No
Common Table Expressions Yes (single + multi-CTE) Raw SQL only Manual Limited
Set operations (Union/Intersect/Except) Yes Yes (LINQ) Manual Yes
Raw SQL with compile-time readers Yes (ordinal-cached) No (runtime binding) Manual No
Conditional branch analysis Yes No No No
Database scaffolding Yes Yes No No
Change tracking No Yes No No
Migrations Yes (code-first, bundles, seed data, views, stored procedures, checksums, squash) Yes No No
Cross-ORM migration converters Yes (EF Core, Dapper, ADO.NET, SqlKata) No No No
Structured logging Yes (Logsmith) Yes (built-in) No No
SQL manifest emission Yes (opt-in) No No No
Prepared multi-terminal queries Yes (all builder types) No No No

Performance

Quarry approaches raw ADO.NET throughput with near-zero framework overhead — faster than Dapper and significantly faster than EF Core or SqlKata. This is possible because the compile-time architecture eliminates entire categories of runtime work:

  • Pre-built SQL string literals — no runtime translation or expression tree walking
  • Ordinal-based readers — no reflection or column-name lookups
  • Carrier dispatch — zero-allocation query execution via generated carrier classes
  • No runtime dependencies — nothing to initialize or warm up

Benchmarks are run against Raw ADO.NET, Dapper, EF Core, and SqlKata using BenchmarkDotNet on an in-memory SQLite database. See the live benchmark dashboard for run-over-run trends with per-commit reports and the benchmark methodology for category descriptions and how to run locally.


Features

  • Compile-time SQL generation — all SQL emitted as string literals at build time; no runtime translation
  • Carrier-only architecture — generated carrier classes hold pre-built SQL, parameters, and conditional dispatch; non-analyzable chains are compile errors
  • Execution interceptors — all terminal methods intercepted with pre-built SQL, ordinal-based readers, and pre-allocated parameter arrays
  • Conditional branch supportif/else query construction emits up to 256 SQL variants dispatched by bitmask at zero runtime cost
  • Prepared queries.Prepare() on all builder types (select, join, insert, update, delete) for reusable multi-terminal execution
  • Zero-allocation readers — ordinal-based Func<DbDataReader, T> delegates generated at compile time
  • Multi-dialect support — SQLite, PostgreSQL, MySQL, SQL Server with correct quoting, parameters, pagination, and identity syntax
  • Type-safe schema DSL — columns as expression-bodied properties; no attributes, no conventions, no runtime model building
  • Navigation joinsOne<T> / HasOne<T>() reverse navigation and HasManyThrough<TTarget,TJunction> many-to-many skip navigation; explicit joins up to 6 tables plus CrossJoin<T>() and FullOuterJoin<T>()
  • Navigation subqueriesAny(), All(), Count(), Sum/Min/Max/Avg(selector) on Many<T> properties compile to correlated subqueries
  • Set operationsUnion/UnionAll/Intersect/IntersectAll/Except/ExceptAll on any query builder, cross-entity supported
  • Window functionsSql.RowNumber/Rank/DenseRank/Ntile/Lag/Lead/FirstValue/LastValue plus aggregate-OVER with fluent PartitionBy/OrderBy
  • Common Table ExpressionsWith<TDto>(dto => …) / FromCte<TDto>(), single and multi-CTE chains, typed post-With accessors via QuarryContext<TSelf>
  • Custom type mappingsTypeMapping<TClr, TDb> with optional IDialectAwareTypeMapping for dialect-specific SQL types
  • Migrations — code-first migrations with bundles, seed data, views/stored procedures, squash, checksums, and runtime hooks
  • Cross-ORM conversionquarry convert --from {dapper|efcore|adonet|sqlkata} with analyzer-driven IDE code fixes (QRM001/011/021/031 diagnostic families)
  • SQL manifest — opt-in per-dialect markdown documenting every generated SQL statement; zero overhead when disabled
  • Scaffolding — reverse-engineer existing databases into schema classes and a context
  • Query diagnosticsToDiagnostics() surfaces SQL, parameters, variants, projection metadata, and carrier class info
  • Structured logging — Logsmith Abstraction mode with categories, slow query detection, sensitive redaction, and operation correlation
  • Analyzer rules — compile-time QRA diagnostics with code fixes
  • Benchmarks — comprehensive BenchmarkDotNet suite comparing Quarry against Raw ADO.NET, Dapper, EF Core, and SqlKata

Installation

<PackageReference Include="Quarry" Version="*" />

Enable interceptors by adding your context's namespace to InterceptorsNamespaces in your .csproj:

<PropertyGroup>
  <InterceptorsNamespaces>$(InterceptorsNamespaces);MyApp.Data</InterceptorsNamespaces>
</PropertyGroup>

Replace MyApp.Data with the namespace containing your QuarryContext subclass. If your context has no namespace, use Quarry.Generated.

Optional: add compile-time query analysis rules:

<PackageReference Include="Quarry.Analyzers" Version="*"
    OutputItemType="Analyzer"
    ReferenceOutputAssembly="false" />

Quick Start

// 1. Define a schema
public class UserSchema : Schema
{
    public static string Table => "users";
    public Key<int> UserId => Identity();
    public Col<string> UserName => Length(100);
    public Col<string?> Email { get; }
    public Col<bool> IsActive => Default(true);
}

// 2. Define a context
[QuarryContext(Dialect = SqlDialect.SQLite)]
public partial class AppDb : QuarryContext
{
    public partial IEntityAccessor<User> Users();
}

// 3. Query
await using var db = new AppDb(connection);

var activeUsers = await db.Users()
    .Select(u => (u.UserName, u.Email))
    .Where(u => u.IsActive)
    .OrderBy(u => u.UserName)
    .Limit(10)
    .ExecuteFetchAllAsync();

The generator emits an interceptor that replaces the ExecuteFetchAllAsync call with pre-built SQL and a typed reader. No runtime translation occurs.


Samples

Sample Description
Quarry.Sample.WebApp ASP.NET Core Razor Pages app with SQLite — demonstrates schema definition, context setup, querying, authentication, migrations, and Logsmith logging integration
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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.4.0 31 5/1/2026
0.3.2 86 4/24/2026
0.3.1 90 4/23/2026
0.3.0 92 4/21/2026
0.2.1 100 3/29/2026
0.2.0 94 3/29/2026
0.1.0 129 3/13/2026