Allegro.Extensions.Dapper
1.2.0
Prefix Reserved
dotnet add package Allegro.Extensions.Dapper --version 1.2.0
NuGet\Install-Package Allegro.Extensions.Dapper -Version 1.2.0
<PackageReference Include="Allegro.Extensions.Dapper" Version="1.2.0" />
paket add Allegro.Extensions.Dapper --version 1.2.0
#r "nuget: Allegro.Extensions.Dapper, 1.2.0"
// Install Allegro.Extensions.Dapper as a Cake Addin #addin nuget:?package=Allegro.Extensions.Dapper&version=1.2.0 // Install Allegro.Extensions.Dapper as a Cake Tool #tool nuget:?package=Allegro.Extensions.Dapper&version=1.2.0
Allegro.Extensions.Dapper
This library contains useful utilities for simpler usage of Dapper library.
In this library you have generic implementation of DatabaseClient which is database agnostic.
You can use already created utilities for specific databases.
- Allegro.Extensions.Dapper.Postgres
Then you will be able to use IDatabaseClient and perform SQL operations.
####If you want to use this library on it's own, please remember to implement IDatabaseConnectionFactory. Example implementation (for Postgres):
public class PostgresDatabaseConnectionFactory : IDatabaseConnectionFactory
{
private readonly DatabaseConfiguration _databaseConfiguration;
public PostgresDatabaseConnectionFactory(
DatabaseConfiguration databaseConfiguration)
{
_databaseConfiguration = databaseConfiguration;
}
public DbConnection Create() =>
new NpgsqlConnection(_databaseConfiguration.ConnectionString);
}
Configure this feature in Startup.cs
:
services
.AddDapperClient()
.AddSingleton(new DatabaseConfiguration
{
ConnectionString = connectionString
})
.AddSingleton<IDatabaseConnectionFactory, PostgresDatabaseConnectionFactory>();
Allegro.Extensions.Dapper.Postgres
This library contains useful utilities for simpler usage for Postgres database with Dapper library.
Remember to configure this feature in Startup.cs
:
services
.AddDapperClient()
.AddDapperPostgres(connectionString);
Then you will be able to use IDapperPostgresBinaryCopyClient and IDapperClient services and perform operations SQL queries against database.
Example usages:
public const string TableName = "TestTable";
//create table
await _dapperClient.ExecuteAsync($@"CREATE TABLE IF NOT EXISTS {TableName}
(
Id SERIAL primary key,
Username VARCHAR(40) UNIQUE
);
");
//drop table
await _dapperClient.ExecuteAsync($@"DROP TABLE IF EXISTS {TableName}");
//insert data into table with returning in transaction
await _dapperClient.ExecuteAndQueryInTransactionAsync<TestTable>($@"
INSERT INTO {TableName}
(
Username
)
VALUES
(
@Username
)
RETURNING
id AS Id,
username AS Username;
");
//query records
await _dapperClient.QueryAsync<TestTable>($@"SELECT
Id,
Username
FROM {TableName});
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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. |
-
net6.0
- Dapper (>= 2.0.123)
- Microsoft.Extensions.DependencyInjection (>= 6.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Allegro.Extensions.Dapper:
Package | Downloads |
---|---|
Allegro.Extensions.Dapper.Postgres
Postgres Dapper clients |
GitHub repositories
This package is not used by any popular GitHub repositories.