Activout.DatabaseClient.Dapper
5.0.0-rc1
dotnet add package Activout.DatabaseClient.Dapper --version 5.0.0-rc1
NuGet\Install-Package Activout.DatabaseClient.Dapper -Version 5.0.0-rc1
<PackageReference Include="Activout.DatabaseClient.Dapper" Version="5.0.0-rc1" />
<PackageVersion Include="Activout.DatabaseClient.Dapper" Version="5.0.0-rc1" />
<PackageReference Include="Activout.DatabaseClient.Dapper" />
paket add Activout.DatabaseClient.Dapper --version 5.0.0-rc1
#r "nuget: Activout.DatabaseClient.Dapper, 5.0.0-rc1"
#:package Activout.DatabaseClient.Dapper@5.0.0-rc1
#addin nuget:?package=Activout.DatabaseClient.Dapper&version=5.0.0-rc1&prerelease
#tool nuget:?package=Activout.DatabaseClient.Dapper&version=5.0.0-rc1&prerelease
Activout Database Client
Create a database client only by defining the C# interface you want. Uses Dapper for object mapping.
Create a Database Access Object (DAO) defining the C# interface you want and writing the SQL query. Shamelessly inspired by Jdbi Declarative API.
Rationale
The Activout Database Client provides a type-safe approach to make SQL requests to the database.
For the actual object mapping, Dapper is used but another implementation can be configured.
Example
public interface IUserDaoAsync
{
[SqlUpdate("CREATE TABLE user (id INTEGER PRIMARY KEY, name VARCHAR)")]
Task CreateTable();
[SqlUpdate("INSERT INTO user(id, name) VALUES (@id, @name)")]
Task InsertNamed([Bind("id")] int id, [Bind("name")] string name);
[SqlUpdate("INSERT INTO user(id, name) VALUES (@id, @name)")]
Task InsertObject([BindProperties] User user);
[SqlUpdate("INSERT INTO user(id, name) VALUES (@user_id, @user_name)")]
Task InsertObjectFull([BindProperties] User user);
[SqlQuery("SELECT * FROM user ORDER BY name")]
Task<IEnumerable<User>> ListUsers();
[SqlQuery("SELECT * FROM user WHERE id = @id")]
Task<User> GetUserById(int id);
}
_userDao = new DatabaseClientBuilder()
.With(new DapperGateway(sqliteConnection))
.Build<IUserDaoAsync>();
await _userDao.CreateTable();
await _userDao.InsertNamed(42, null);
var user = await _userDao.GetUserById(42);
Full example code in DatabaseClientAsyncTest.cs.
Example with dependency injection
// Connection string example for MySQL:
// "Server=example.com;Database=example;User=example;Password=example;AutoEnlist=True;Pooling=True;ConnectionReset=True;CharSet=utf8mb4;"
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
builder.Services.AddScoped<IDbConnection>(_ => new MySqlConnection(connectionString));
builder.Services.AddScoped<DatabaseClientBuilder>();
builder.Services.AddScoped<IDatabaseClient>(sp => sp
.GetRequiredService<DatabaseClientBuilder>()
.With(new DapperGateway(sp.GetRequiredService<IDbConnection>()))
.Build<IDatabaseClient>());
builder.Services.AddTransient<SomeService>();
// ...
public class SomeService(IDatabaseClient databaseClient)
{
// ...
}
Collaborate
This project is still under development - participation welcome!
Related projects
- Activout.RestClient - Create a REST(ish) API client only by defining the C# interface you want.
About Activout
Activout AB is a software company in Ronneby, Sweden.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. |
-
net8.0
- Activout.DatabaseClient (>= 5.0.0-rc1)
- Dapper (>= 2.1.66)
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 |
|---|---|---|
| 5.0.0-rc1 | 357 | 3/4/2025 |
| 4.0.0 | 335 | 1/11/2025 |
| 3.0.0-beta | 503 | 10/17/2020 |
| 1.0.1 | 1,778 | 12/2/2018 |