RS.Dapper.Utility
1.0.2
See the version list below for details.
dotnet add package RS.Dapper.Utility --version 1.0.2
NuGet\Install-Package RS.Dapper.Utility -Version 1.0.2
<PackageReference Include="RS.Dapper.Utility" Version="1.0.2" />
<PackageVersion Include="RS.Dapper.Utility" Version="1.0.2" />
<PackageReference Include="RS.Dapper.Utility" />
paket add RS.Dapper.Utility --version 1.0.2
#r "nuget: RS.Dapper.Utility, 1.0.2"
#:package RS.Dapper.Utility@1.0.2
#addin nuget:?package=RS.Dapper.Utility&version=1.0.2
#tool nuget:?package=RS.Dapper.Utility&version=1.0.2
RS.Dapper.Utility
A lightweight utility library built on top of Dapper to simplify and standardize database operations across MSSQL, PostgreSQL, and MySQL. All are managed by appsettings.json and DbSchema.cs class
✅ Features
IDapperExecutor
for executing SQL queries and stored procedures easily.IDapperRepository
for generic CRUD operations along with pagination and search.- Support for:
ExecuteAsync
ExecuteScalarAsync
QueryAsync
QueryFirstOrDefaultAsync
QueryMultipleAsync
- Works with DynamicParameters and anonymous objects.
- Designed for Dependency Injection and unit testing.
📦 Installation
Install from NuGet (https://www.nuget.org/packages/RS.Dapper.Utility):
dotnet add package RS.Dapper.Utility
⚡ Quick Start
Add your database settings in appsettings.json.
"Databases": {
"MealFormulaDb": {
"DbType": "SqlServer",
"ConnectionString": "Server=195.250.xx.xx;User ID=rsinnov7_mf;password=xxxxx;database=dbname;Encrypt=True;TrustServerCertificate=True;"
},
"CategoriesDb": {
"DbType": "MySql",
"ConnectionString": ""
},
"ProductsDb": {
"DbType": "PostgreSql",
"ConnectionString": ""
}
}
1. Register Services
Add to your Program.cs:
- DbSchema.cs serves as a bridge between the application code and RS.Dapper.Utility, centralizing database names, schemas, and table mappings for consistency and maintainability.
- Download DbSchema.cs class from GitHub and add in your poroject DbSchema.cs
- Setup DbSchema for RS_DapperUtility, it is part of Utility but it is open to manage by developer as they have to add table(s)and proc(s) names
DbSchema.Initialize(builder.Configuration);
//Inject RS_DapperUtilityDependencyInjections
builder.Services.RS_DapperUtilityDependencyInjections(builder.Configuration);
//Start-****************Setup SqlBuilder IMemoryCache for RS_DapperUtility **************
var memoryCache = app.Services.GetRequiredService<IMemoryCache>();
SqlBuilder.Initialize(memoryCache);
//End-*****************Setup SqlBuilder IMemoryCache for RS_DapperUtility****************
- For more detail check API Program.cs class on GitHub
How to use RS.Dapper Attributes
Please use ToParametersForInsert and ToParametersForUpdate, it helps for auto column mapping, and use Attributes like following:-
- [IgnoreOnInsert] // Exclude Id during insert, if it auto generated, else set your Id in Service class such as GUID
- [SqlParam("full_name")]//Just for example, we will use param full_name in PROC or it will also create select/insert prop mapping in SQL query.
[IgnoreOnInsert] // Exclude Id during insert
public virtual long Id { get; set; }
[SqlParam("Icon")]// In this case we have Icon column name in database and prop name is Image
public string Image { get; set; }
2. Example: Execute Stored Procedure
await _dapperExecutor.ExecuteAsync(DbSchema.UsersDbName, DbSchema.UserInsertProc, user.ToParametersForInsert());
await _dapperExecutor.ExecuteAsync(DbSchema.UsersDbName,DbSchema.UserDeleteProc,new { Id = id });
await _dapperExecutor.QueryFirstOrDefaultAsync<UserModel>(DbSchema.UsersDbName, DbSchema.UserGetByIdProc, new { Id = id });
await _dapperExecutor.ExecuteAsync(DbSchema.UsersDbName, DbSchema.UserUpdateProc, user.ToParametersForUpdate());
3. Example: Insert using Repository
💡 In today’s world, databases are already highly optimized and blazing fast. For common operations like Insert, Update, Delete, or Select, we don’t always need to write stored procedures anymore.
With RS.Dapper.Utility, we can achieve all of this dynamically and cleanly — without the extra overhead of manual SQL or stored procs.
🚀 Good news! RS.Dapper.Utility now supports a Paging SQL Query Builder 🎉. You can also define your own search columns for flexible filtering.
⚠️ Note: When working with data across multiple tables, it’s still best to use a stored procedure(chcek 4 point) or write a raw query — and then execute it using RS.Dapper.Utility’s DapperExecutor.
🚀 OMG one line code and we are done with CURD
await _dapperRepository.InsertAsync(request,DbSchema.CategoriesDbName, DbSchema.CategoryTable);
await _dapperRepository.UpdateAsync(request, DbSchema.CategoriesDbName, DbSchema.CategoryTable);
await _dapperRepository.DeleteAsync(id, DbSchema.CategoriesDbName, DbSchema.CategoryTable);
await _dapperRepository.GetAllAsync<CategoryResponse>(DbSchema.CategoriesDbName, DbSchema.CategoryTable);
await _dapperRepository.GetByIdAsync<CategoryModel,int>(id, DbSchema.CategoriesDbName, DbSchema.CategoryTable);
await _dapperRepository.GetPagedDataAsync<CategoryResponse>(DbSchema.CategoriesDbName, DbSchema.CategoryTable, pagedRequest);
4. Query Multiple Result Sets with PROC
using var multi = await _dapperExecutor.QueryMultipleAsync(DbSchema.CategoriesDbName,
DbSchema.UserGetWithRoles,
new { Id = 1 }
);
var user = await multi.ReadFirstOrDefaultAsync<UserModel>();
var roles = await multi.ReadAsync<RoleModel>();
✅ License
This project is licensed under the MIT License.
SPDX-License-Identifier: MIT
See the LICENSE file for details.
🔗 Links
✅ How I am using RS.Dapper.Utility
I use RS.Dapper.Utility in my projects, and it saves me a huge amount of development and testing time.
👉 For 95% of CRUD operations, I rely on IDapperRepository. 👉 For the remaining 5%, I use IDapperExecutor when I need to work with stored procedures.
I’m not against stored procedures—they’re still great for complex queries across multiple tables (insert/update/select). But with RS.Dapper.Utility, you have the freedom to choose:
Go fully with IDapperRepository for simplicity and speed
Or combine it with IDapperExecutor where it makes sense
⚡ One of the biggest advantages: Database switching.
If your app is 100% on IDapperRepository, moving from SQL Server to MySQL or PostgreSQL takes just 5 minutes.
Even if you’re 95% repository + 5% stored procedures, it still only takes about 1 hour.
📌 RS.Dapper.Utility is open-source and open for contributions. You can download, customize, and enhance it:
💡 Bonus: On the same GitHub repo, I also share ready-to-use project templates and working code samples—new content added every week to help developers save time.
🔥 If you’re a .NET developer looking for speed, flexibility, and clean database access with Dapper—RS.Dapper.Utility is built for you.
☕ Buy Me A Coffee Your support motivates me to keep adding more developer-friendly utilities 🚀
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
- Dapper (>= 2.1.66)
- Microsoft.Data.SqlClient (>= 6.0.2)
- Microsoft.Extensions.Caching.Memory (>= 9.0.7)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.6)
- MySql.Data (>= 9.4.0)
- Npgsql (>= 9.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
🚀 Version 1.0.2
This release introduces major improvements in connection management and multi-database support.
✨ What’s New
Removed DapperContext class – database connections are now resolved through the new DatabaseResolver.
Multiple database support – RS.Dapper.Utility now works seamlessly with one or more databases, configured via appsettings.json.
Unified configuration – databases are defined in the Databases section:
"Databases": {
"MealFormulaDb": {
"DbType": "SqlServer",
"ConnectionString": "Server=1..;User ID=...;Password=...;Database=...;Encrypt=True;TrustServerCertificate=True;"
},
"CategoriesDb": {
"DbType": "MySql",
"ConnectionString": ""
},
"ProductsDb": {
"DbType": "PostgreSql",
"ConnectionString": ""
}
}
Supports SQL Server, MySQL, and PostgreSQL.
Centralized connection handling – the library automatically selects the correct database provider based on configuration.
🔧 Benefits
- Cleaner architecture with no direct dependency on DapperContext.
- Developers now have full control over multiple databases without code changes.
- Simplified and consistent approach for cross-database applications.