DreamBig.SourceGen.Dapper.SqlServer 1.0.0-beta.10

This is a prerelease version of DreamBig.SourceGen.Dapper.SqlServer.
dotnet add package DreamBig.SourceGen.Dapper.SqlServer --version 1.0.0-beta.10
                    
NuGet\Install-Package DreamBig.SourceGen.Dapper.SqlServer -Version 1.0.0-beta.10
                    
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="DreamBig.SourceGen.Dapper.SqlServer" Version="1.0.0-beta.10" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DreamBig.SourceGen.Dapper.SqlServer" Version="1.0.0-beta.10" />
                    
Directory.Packages.props
<PackageReference Include="DreamBig.SourceGen.Dapper.SqlServer" />
                    
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 DreamBig.SourceGen.Dapper.SqlServer --version 1.0.0-beta.10
                    
#r "nuget: DreamBig.SourceGen.Dapper.SqlServer, 1.0.0-beta.10"
                    
#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 DreamBig.SourceGen.Dapper.SqlServer@1.0.0-beta.10
                    
#: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=DreamBig.SourceGen.Dapper.SqlServer&version=1.0.0-beta.10&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=DreamBig.SourceGen.Dapper.SqlServer&version=1.0.0-beta.10&prerelease
                    
Install as a Cake Tool

DreamBig.SourceGen.Dapper

DreamBig.SourceGen.Dapper provides compile-time SQL generation for Dapper users who want to avoid raw SQL in application code.

Features

  • Attribute-driven repository generation ([DbRepository])
  • Entity mapping attributes ([DbTable], [DbColumn], [DbKey], [DbIgnore])
  • Generated CRUD methods
  • Generated stored procedure execution with output parameter support
  • Generated INNER/OUTER joins from method-level attributes
  • Provider-specific SQL generation (SQL Server and PostgreSQL)

Target Frameworks

Runtime library supports:

  • net10.0

Install

  • SQL Server: DreamBig.SourceGen.Dapper
  • PostgreSQL: DreamBig.SourceGen.Dapper.PostgreSql

DI Setup

SQL Server:

using DreamBig.SourceGen.Dapper.SqlServer;

services.AddDreamBigDapperSqlServer(configuration);
services.AddDreamBigDapperGenerated();

PostgreSQL:

using DreamBig.SourceGen.Dapper.PostgreSql;

services.AddDreamBigDapperPostgreSql(configuration);
services.AddDreamBigDapperGenerated();

Configuration sections:

  • SQL Server: DreamBig:Dapper:SqlServer
  • PostgreSQL: DreamBig:Dapper:PostgreSql

Overloads are available for raw connection strings and custom connection string factories.

Quick Start

using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using DreamBig.SourceGen.Dapper.Attributes;

[DbTable("Customers", Schema = "dbo")]
public sealed class Customer
{
    [DbKey]
    public int Id { get; set; }

    [DbColumn("full_name")]
    public string Name { get; set; } = string.Empty;

    public string Email { get; set; } = string.Empty;
}

[DbRepository]
public interface ICustomerRepository
{
    Task<int> InsertCustomer(Customer entity, CancellationToken cancellationToken);
    Task<int> UpdateCustomer(Customer entity, CancellationToken cancellationToken);
    Task<int> DeleteCustomer(int id, CancellationToken cancellationToken);
    Task<Customer?> GetByIdCustomer(int id, CancellationToken cancellationToken);
    Task<IEnumerable<Customer>> GetAllCustomers(CancellationToken cancellationToken);
}

The source generator emits CustomerRepositoryGenerated, with SQL and Dapper calls already implemented.

Primary Key Without [DbKey]

You can define the primary key directly on DbTableAttribute using PrimaryKey. This is useful when the entity class comes from another team/package and you do not want to modify the entity source.

using System.Threading;
using System.Threading.Tasks;
using DreamBig.SourceGen.Dapper.Attributes;

[DbTable("Customers", Schema = "dbo", PrimaryKey = "CustomerId")]
public sealed class ExternalCustomer
{
    public int CustomerId { get; set; }
    public string Name { get; set; } = string.Empty;
}

[DbRepository]
public interface IExternalCustomerRepository
{
    Task<int> UpdateCustomer(ExternalCustomer entity, CancellationToken cancellationToken);
    Task<int> DeleteCustomer(int customerId, CancellationToken cancellationToken);
    Task<ExternalCustomer?> GetByIdCustomer(int customerId, CancellationToken cancellationToken);
}

PrimaryKey can match either:

  • the CLR property name (CustomerId), or
  • the mapped SQL column name when DbColumnAttribute is used.

Join Example

using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using DreamBig.SourceGen.Dapper.Attributes;

[DbQuery(From = "Customers", Schema = "dbo", Where = "[IsActive] = @isActive", OrderBy = "Id", OrderByDirection = OrderByDirection.Desc)]
[DbJoin(JoinType = JoinType.Left, JoinTable = typeof(Order), JoinColumnA = "Id", JoinColumnB = "CustomerId", Schema = "sales")]
Task<IEnumerable<CustomerSummary>> QueryActive(bool isActive, CancellationToken cancellationToken);

Notes:

  • The generator assigns table aliases (t0, t1, ...) automatically.
  • OrderBy expects a column/property name only; use OrderByDirection to control sort direction.
  • JoinColumnA and JoinColumnB must match CLR property names on the base entity and join entity (validated at compile time).

Stored Procedure Example

using System.Data;
using System.Threading;
using System.Threading.Tasks;
using DreamBig.SourceGen.Dapper.Attributes;
using DreamBig.SourceGen.Dapper.Internal;

[DbStoredProcedure("usp_customer_summary", Schema = "dbo")]
Task<GeneratedProcedureResult<CustomerSummary>> GetSummary(
    [DbParam("@customerId", DbType = DbType.Int32)] int customerId,
    [DbParam("@total", Direction = DbParamDirection.Output)] int total,
    CancellationToken cancellationToken);

Unit Of Work Example

using System;
using System.Threading;
using System.Threading.Tasks;
using DreamBig.SourceGen.Dapper.Attributes;

[DbUnitOfWork]
public interface IAppUnitOfWork
{
    ICustomerRepository Customers { get; }
    IOrderRepository Orders { get; }
}

// generated type: AppUnitOfWorkGenerated
var uow = new AppUnitOfWorkGenerated(() => new SqlConnection(connectionString));

await uow.BeginTransactionAsync(cancellationToken: cancellationToken);
try
{
    await uow.Customers.UpdateCustomer(customer, cancellationToken);
    await uow.Orders.DeleteOrder(orderId, cancellationToken);
    await uow.CommitAsync(cancellationToken);
}
catch
{
    await uow.RollbackAsync(cancellationToken);
    throw;
}

Notes:

  • Insert*, Update*, Delete*, and stored procedure methods require an active transaction and throw InvalidOperationException otherwise.
  • Read/query methods can execute with or without an active transaction.

Known Limitations (v1)

  • SQL dialect support is limited to SQL Server and PostgreSQL.
  • Stored procedures support one mapped result set plus output parameter capture.
  • Complex projection/multi-mapping scenarios are not yet generated.

Dialect Packages

The generator emits SQL based on the provider-specific package you install (DreamBig.SourceGen.Dapper for SQL Server, DreamBig.SourceGen.Dapper.PostgreSql for PostgreSQL) while preserving the same attribute contracts.

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
1.0.0-beta.10 30 3/15/2026
1.0.0-beta.9 27 3/15/2026
1.0.0-beta.8 44 3/14/2026