Dapper.SqlGenerator 1.1.3

dotnet add package Dapper.SqlGenerator --version 1.1.3
NuGet\Install-Package Dapper.SqlGenerator -Version 1.1.3
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="Dapper.SqlGenerator" Version="1.1.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Dapper.SqlGenerator --version 1.1.3
#r "nuget: Dapper.SqlGenerator, 1.1.3"
#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.
// Install Dapper.SqlGenerator as a Cake Addin
#addin nuget:?package=Dapper.SqlGenerator&version=1.1.3

// Install Dapper.SqlGenerator as a Cake Tool
#tool nuget:?package=Dapper.SqlGenerator&version=1.1.3

Dapper.SqlGenerator

Database agnostic SQL code generation for Dapper without POCO attributes and Entity Framework Core compatible schema definition.

Usage and examples

Dapper.SqlGenerator.Async

Dapper database agnostic async SELECT, INSERT, UPDATE, DELETE, MERGE queries and a file or resource database migration tool

Usage and examples

Dapper.SqlGenerator Quick Start

Create model from db:

dotnet ef dbcontext scaffold "Server=.\SQLEXPRESS;Database=MyDb;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o Models

Use the model above:

OnModelCreating(DapperSqlGenerator.Configure());

Available functions:

using Dapper.SqlGenerator;

string insertSql = connection.Sql().Insert<Product>();
string insertAndReturnSql = connection.Sql().InsertReturn<Product>();
string updateSql = connection.Sql().Update<Product>();
string deleteSql = connection.Sql().Delete<Product>();
string tableName = connection.Sql().Table<Order>();
string commaSeparatedNonKeyColumns = connection.Sql().GetColumns<Order>(ColumnSelection.NonKeys | ColumnSelection.Computed);
string keysAtQueryParams = connection.Sql().GetParams<Order>(ColumnSelection.Keys);
string columnEqualParams = connection.Sql().GetColumnEqualParams<Order>(ColumnSelection.NonKeys);

connection.Sql().HasColumnSet("unique_order", x => x.OrderId, x => x.ProductId);
string upsertMergeSql = connection.Sql().Merge<Order>("unique_order");

Dapper.SqlGenerator.Async Quick Start

SELECT and CRUD:

using Dapper.SqlGenerator;
using Dapper.SqlGenerator.Async;

connection.Sql().HasColumnSet<Product>("id+kind+content", x => x.Id, x => x.Kind, x => x.Content);

var all = await connection.SelectAsync<Product>();
var allWithSomeColumns = await connection.SelectAsync<Product>("id+kind+content");
var filtered = await connection.SelectWhereAsync<Product>("WHERE Kind > 5");
var firstWithSomeColumns = await connection.SelectFirstAsync<Product>(new { Id = 1 }, "id+kind+content");
var fisrtOrNull = connection.SelectFirstOrDefaultAsync<Product>(new { Id = -1 });
var single =  = await connection.SelectSingleAsync<Product>(new { Id = 1 });
var singleOrNull =  = await connection.SelectSingleOrDefaultAsync<Product>(new { Id = 1 });

var rows1 = await connection.InsertAsync(new Product { Kind = 4, Content = "Square" });
var inserted1 = await connection.InsertReturnAsync(new Product { Kind = 7, Content = "Triangle" });
var rows2 = await connection.UpdateAsync(new Product { Id = 1, Kind = 66, Content = "Modified" });
var deleted = await connection.DeleteAsync(new Product { Id = 2 });

connection.Sql().HasColumnSet<Product>("content", x => x.Content);
var insertedOrUpdated = await connection.MergeAsync(new Product { Kind = 7, Content = "Triangle", Value = 123 }, "content", "id+kind+content");

Database migration from scripts embedded as resources in MigrationResources namespace, for Sqlite:

using Dapper.SqlGenerator.Async.Migration;

var connectionString = "Data Source=:memory:";
await using var connection = new SQLiteConnection(connectionString);
connection.Open();

var namespaceName = Assembly.GetExecutingAssembly().GetName().Name + ".MigrationResources";
var noMigrationsApplied = await connection.InitDatabase(Assembly.GetExecutingAssembly(), namespaceName);
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Dapper.SqlGenerator:

Package Downloads
Dapper.SqlGenerator.Async

Runs Dapper queries using SqlGenerator for generating and caching SQL, does not have any dependencies other than Dapper and generates modern SQL depending on a connection type while being fully customizable

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.3 1,034 11/6/2020
1.1.1 524 11/3/2020
1.1.0 663 11/1/2020
1.0.7 409 10/24/2020
1.0.6 444 10/24/2020
1.0.5 420 10/17/2020
1.0.4 384 10/15/2020
1.0.3 399 10/15/2020
1.0.2 409 10/15/2020
1.0.1 390 10/14/2020
1.0.0 396 10/14/2020