Dapper.SqlGenerator.Async
1.1.0
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
<PackageReference Include="Dapper.SqlGenerator.Async" Version="1.1.0" />
<PackageVersion Include="Dapper.SqlGenerator.Async" Version="1.1.0" />
<PackageReference Include="Dapper.SqlGenerator.Async" />
paket add Dapper.SqlGenerator.Async --version 1.1.0
#r "nuget: Dapper.SqlGenerator.Async, 1.1.0"
#:package Dapper.SqlGenerator.Async@1.1.0
#addin nuget:?package=Dapper.SqlGenerator.Async&version=1.1.0
#tool nuget:?package=Dapper.SqlGenerator.Async&version=1.1.0
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 | Versions 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. |
-
.NETStandard 2.1
- Dapper (>= 2.0.35)
- Dapper.SqlGenerator (>= 1.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.