Galosys.Foundation.Dapper
26.9.10.1
dotnet add package Galosys.Foundation.Dapper --version 26.9.10.1
NuGet\Install-Package Galosys.Foundation.Dapper -Version 26.9.10.1
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="Galosys.Foundation.Dapper" Version="26.9.10.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Galosys.Foundation.Dapper" Version="26.9.10.1" />
<PackageReference Include="Galosys.Foundation.Dapper" />
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 Galosys.Foundation.Dapper --version 26.9.10.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Galosys.Foundation.Dapper, 26.9.10.1"
#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 Galosys.Foundation.Dapper@26.9.10.1
#: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=Galosys.Foundation.Dapper&version=26.9.10.1
#tool nuget:?package=Galosys.Foundation.Dapper&version=26.9.10.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Galosys.Foundation.Dapper
成熟度: 🟢 稳定 — 生产可用,测试充分,活跃维护
简介
Galosys.Foundation.Dapper 基于 Dapper 提供轻量级 ORM 和数据访问支持,包含工作单元模式、SQL 映射、CDC(变更数据捕获)等功能。
特性
- Dapper 集成 - 高性能轻量级 ORM
- 工作单元模式 (UnitOfWork) - 事务管理
- SQL 映射 - 静态 SQL 查询映射
- SQL 构建器 - 动态 SQL 构建
- CDC 监听器 - 变更数据捕获(支持 SQL Server)
- 支持多种数据库 - SQL Server, Oracle 等
安装
dotnet add package Galosys.Foundation.Dapper
使用
工作单元
public class OrderRepository
{
private readonly IUnitOfWork _unitOfWork;
public OrderRepository(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
public async Task InsertOrderAsync(Order order)
{
var sql = "INSERT INTO Orders (Id, OrderNo, Amount) VALUES (@Id, @OrderNo, @Amount)";
await _unitOfWork.ExecuteAsync(sql, order);
}
public async Task CommitAsync()
{
await _unitOfWork.CommitAsync();
}
}
查询示例
public class UserService
{
private readonly IDbConnection _db;
public UserService(IDbConnection db)
{
_db = db;
}
public async Task<IEnumerable<User>> GetUsersAsync()
{
var sql = "SELECT * FROM Users WHERE Deleted = 0";
return await _db.QueryAsync<User>(sql);
}
public async Task<User> GetUserByIdAsync(long id)
{
var sql = "SELECT * FROM Users WHERE Id = @Id";
return await _db.QueryFirstOrDefaultAsync<User>(sql, new { Id = id });
}
public async Task<int> InsertUserAsync(User user)
{
var sql = @"INSERT INTO Users (Name, Email) VALUES (@Name, @Email);
SELECT CAST(SCOPE_IDENTITY() as bigint)";
return await _db.ExecuteScalarAsync<int>(sql, user);
}
}
SQL 映射
// 使用 SqlMap 进行静态 SQL 映射
var result = await SqlMap.QueryAsync<User>("SelectUsers");
CDC 监听(变更数据捕获)
public class OrderCdcListener : ICdcListener
{
public DatabaseType DatabaseType => DatabaseType.SqlServer;
public string[] TableNames => new[] { "Orders" };
public async Task HandleAsync(CdcEventArgs args)
{
// 处理变更数据
Console.WriteLine($"Operation: {args.Operation}");
Console.WriteLine($"Data: {args.Data}");
}
}
// 注册 CDC 监听器
services.AddCdcListener<OrderCdcListener>();
分页查询
public async Task<PageOutput> GetUserPageAsync(int page, int size)
{
var sql = "SELECT * FROM Users ORDER BY Id OFFSET @Offset ROWS FETCH NEXT @Size ROWS ONLY";
var countSql = "SELECT COUNT(*) FROM Users";
var items = await _db.QueryAsync<User>(sql, new { Offset = (page - 1) * size, Size = size });
var total = await _db.ExecuteScalarAsync<int>(countSql);
return PageOutput.Of(items, total, page, size);
}
核心类
| 类 | 说明 |
|---|---|
DapperUnitOfWork |
Dapper 工作单元实现 |
SqlMap |
SQL 静态映射 |
SqlBuilderExtensions |
SQL 构建扩展 |
MssqlCdcListener |
SQL Server CDC 监听器 |
ICdcListener |
CDC 监听器接口 |
依赖
- Dapper
- Microsoft.Data.SqlClient (SQL Server)
- Oracle.ManagedDataAccess.Core (Oracle)
- Galosys.Foundation.Core
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- dapper (>= 2.1.66)
- dapper.sqlbuilder (>= 2.1.66)
- Galosys.Foundation.Data (>= 26.9.10.1)
- microsoft.data.sqlclient (>= 6.0.1)
- microsoft.data.sqlite (>= 8.0.8)
- MySqlConnector (>= 2.4.0)
- npgsql (>= 10.0.2)
- Oracle.ManagedDataAccess.Core (>= 3.21.140)
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 |
|---|---|---|
| 26.9.10.1 | 7 | 9/10/2026 |
| 26.9.3.1 | 88 | 9/3/2026 |
| 26.8.29.1 | 85 | 8/31/2026 |
| 26.8.26.1 | 96 | 8/26/2026 |
| 26.8.23.1 | 95 | 8/23/2026 |
| 26.8.21.1 | 88 | 8/21/2026 |
| 26.8.20.1 | 93 | 8/20/2026 |
| 26.8.18.1 | 94 | 8/18/2026 |
| 26.8.17.1 | 107 | 8/17/2026 |
| 26.8.13.2 | 92 | 8/13/2026 |
| 26.8.13.1 | 98 | 8/13/2026 |
| 26.8.12.2 | 94 | 8/12/2026 |
| 26.8.12.1 | 97 | 8/12/2026 |
| 26.8.10.1 | 96 | 8/10/2026 |
| 26.8.5.1 | 99 | 8/5/2026 |
| 26.8.4.1 | 105 | 8/4/2026 |
| 26.8.3.1 | 103 | 8/3/2026 |
| 26.7.31.1 | 103 | 7/31/2026 |
| 26.7.30.1 | 108 | 7/30/2026 |
| 26.7.29.1 | 103 | 7/29/2026 |
Loading failed