Dapper.SqlGenerator.Async 1.1.0

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

Dapper.SqlGenerator.Async Usage - Select

All typed Dapper Query variants are available, some example SELECT queries:

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 });

Dapper.SqlGenerator.Async Usage - INSERT, UPDATE, DELETE, MERGE

using Dapper.SqlGenerator.Async;

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

// note id column although in the set will not be inserted as it is a key
var affectedRows = await connection.InsertAsync(new Product { Kind = 4, Content = "Square" }, "id+kind+content");
// id will be inserted
var affectedRowsInsertedId = await connection.InsertAsync(new Product { Id = 1234, Kind = 4, Content = "Circle" }, "id+kind+content", true);

// inserted1.Id will have the newly inserted Id
var inserted1 = await connection.InsertReturnAsync(new Product { Kind = 7, Content = "Triangle" });

// only Kind and Content columns will be modified
var affectedUpdateRows = await connection.UpdateAsync(new Product { Id = 1, Kind = 66, Content = "Modified" }, "id+kind+content");

var affectedDeleteRows = await connection.DeleteAsync(new Product { Id = 2 });

// Content column is considered unique
connection.Sql().HasColumnSet<Product>("content", x => x.Content);
connection.Sql().HasColumnSet<Product>("id+kind+content+value", x => x.Id, x => x.Kind, x => x.Content, x => x.Value);
var affectedInsertOrUpdateRows = await connection.MergeAsync(new Product { Kind = 7, Content = "Triangle", Value = 123 }, "content", "id+kind+content+value");

Dapper.SqlGenerator.Async Usage - Migrations

Resources containing SQL scripts must have an extension which is either "sql" (can be changed using options) or the name of ISqlAdapter class, lowercase i.e. "npgsqlconnection". Resource name should be prepared for correct ordering when applying migrations.

For example having folloging scripts:

20200101-init-database.sql
20200101-init-database.sqliteconnection
  • on SqliteConnection .sqliteconnection will execute first and .sql second, both in a same transaction
  • on any other connectionn, only .sql will execute
  • only one migration '20200101-init-database' will be added to the database when migration completed successfully

Example to prepare a 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.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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.

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.1.3 915 11/6/2020
1.1.2 555 11/3/2020
1.1.1 566 11/3/2020
1.1.0 562 11/1/2020