Aore.DapperHelper
1.8.5
dotnet add package Aore.DapperHelper --version 1.8.5
NuGet\Install-Package Aore.DapperHelper -Version 1.8.5
<PackageReference Include="Aore.DapperHelper" Version="1.8.5" />
<PackageVersion Include="Aore.DapperHelper" Version="1.8.5" />
<PackageReference Include="Aore.DapperHelper" />
paket add Aore.DapperHelper --version 1.8.5
#r "nuget: Aore.DapperHelper, 1.8.5"
#:package Aore.DapperHelper@1.8.5
#addin nuget:?package=Aore.DapperHelper&version=1.8.5
#tool nuget:?package=Aore.DapperHelper&version=1.8.5
Aore.DapperHelper — .NET SDK
📈 一个基于 .NET Standard 2.0 和Dapper的数据库操作工具库,提供了多种数据访问和实用功能的组件,提供了丰富的数据库操作方法和事务管理功能。我将继续保持更新,并正在深度融合更多场景应用👐
使用 Aore.DapperHelper,您可以方便快速将现有项目或新项目实现操作数据库支持。
目前 Aore.DapperHelper 支持 .NET Standard 2.0 等多种框架,同时兼容所有 MVC、Razor、WebApi、Console(命令行)、桌面应用(.exe)和后台服务等环境,和外部框架完全解耦。
希望有更多的人可以从中受益,理解并传播开源的精神,一同助力中国开源事业!感恩一路上给我们提供帮助的朋友们!
如果你喜欢并希望我们继续优化这个项目,请给我们一个 ★Star :)
✨ 功能特性
- 数据库连接管理: 自动管理数据库连接的打开、关闭和释放
- 事务支持: 提供完整的事务管理功能,包括事务的开始、提交和回滚
- 多种查询方式: 支持同步和异步查询,包括返回 DataTable、DataRow、字符串等格式
- 批量操作: 支持批量执行 SQL 语句,提供事务和非事务两种模式
- 存储过程支持: 可以执行存储过程并处理输入输出参数
- Dapper Contrib 集成: 集成了 Dapper.Contrib,支持实体的增删改查操作
- 参数处理: 自动处理参数化查询和列表参数
- 扩展性: 作为基类,可被继承以创建特定数据库的实现
🚀Aore.DapperHelper 操作示例 :开启你的改造开发之旅!
.NET CLI:
dotnet add package Aore.DapperHelper
或
Nuget包进行搜索下载
🛠 初始化 Aore.DapperHelper
// 方式一:继承DbHelperBase类快速实现指定数据的Helper
public class MyDbHelper : DbHelperBase<MyEntity>
{
public override string ConnectionString => "your_connection_string_here";
public override IDbConnection Connection => new SqlConnection(ConnectionString);
}
var dbHelper = new MyDbHelper();
// 方式二:可以直接使用DbHelper和DapperHelper两个类,传入数据库连接地址(默认支持Oracle),也可以支持指定数据库加对应连接地址
var dbHelper = new DbHelper<object>("your_connection_string_here");
var dbHelper = new DbHelper<object>(DBType.SqlServer,"your_connection_string_here");
操作指定类型的数据库,需要在项目中引用对应数据库的驱动dll依赖,例如:Oracle数据库需要引用Oracle.ManagedDataAccess.dll依赖
🔍 基本查询操作
- Query<T>(
重载参数): 执行查询并返回指定类型的集合 - QueryFirst<T>(
重载参数): 执行查询并返回第一个结果 - QueryFirstOrDefault<T>(
重载参数): 执行查询并返回第一个结果或默认值 - QueryDataTable(
重载参数): 执行查询并返回 DataTable - QueryString(
重载参数): 执行查询并返回单个字符串值
☑️ 异步查询操作
- QueryAsync<T>(
重载参数): 异步执行查询并返回指定类型的集合 - QueryFirstAsync<T>(
重载参数): 异步执行查询并返回第一个结果 - QueryFirstOrDefaultAsync<T>(
重载参数): 异步执行查询并返回第一个结果或默认值 - QueryDataTableAsync(
重载参数): 异步执行查询并返回 DataTable
✨ 实体操作 (Dapper.Contrib)
- Get<T>(
重载参数): 根据主键获取实体 - GetAll<T>(
重载参数): 获取所有实体 - Insert<T>(
重载参数): 插入实体 - Update<T>(
重载参数): 更新实体 - Delete<T>(
重载参数): 删除实体
🕶️ 执行操作
- Execute(
重载参数): 执行非查询 SQL 语句 - ExecuteAsync(
重载参数): 异步执行非查询 SQL 语句
📚 批量操作
- BatchExecutionForeach(
重载参数): 批量执行 SQL 列表(使用事务) - BatchExecutionBeginEnd(
重载参数): 使用 BEGIN/END 块批量执行 SQL 列表(使用事务)
🛡️ 事务管理
- BeginTransaction(
重载参数): 开始事务 - OpenConnection(
重载参数): 打开数据库连接
🌏 存储过程
- ExecuteProcedure(
重载参数): 执行存储过程
📚 使用示例
// 查询示例
var users = dbHelper.Query<User>("SELECT * FROM Users WHERE Age > :Age", new { Age = 18 });
// 批量操作示例
var sqlList = new List<string>
{
"UPDATE Users SET Status = 'Active' WHERE Age >= 18",
"DELETE FROM Users WHERE Status = 'Inactive'"
};
var result = dbHelper.BatchExecutionForeach(sqlList);
// ...
📢 更新记录
[1.8.5]
- 修复GetDBType方法调用错误,统一使用GetDbType方法名
- 移除DapperHelper和DbHelper中的析构函数,避免资源管理问题
- 在DbHelperBase中添加System.Text命名空间引用
- 将连接相关属性从public改为protected,并添加_disposed标识和默认常量
- 将所有自动dispose替换为ManualDispose方法,改进资源管理
- 重写BatchExecutionForeach方法,实现分批执行和错误处理机制
- 新增带分批数量和超时参数的批量执行重载方法
- 优化BatchExecutionBeginEnd方法,支持分批执行和命令超时设置
- 更新异步批量执行方法,支持自定义分批数量和超时时间
- 重命名存储过程参数名,从大写改为小写驼峰命名
- 为所有数据库操作方法添加手动资源释放机制
[1.0.0]
- 数据效能优化,修改IDbConnectio的打开关闭,避免长时间占用数据库连接,导致DBA连接数过多
- 添加对常用数据库的支持(Sql Service、Oracle、OleDb、MySQL、PostgreSQL、SQLite、Odbc...)没有指定DbType时,默认使用Oracle
- 调整类库包结构,优化类库包的引用
- 添加公共连接抽象DapperHelperBase,不同数据库连接类(OracleDataBase、SqlDataBase、MySqlDataBase)继承(DapperHelperBase)类
- DapperHelper限定使用统一的参数标识前缀[:],为满足SqlService参数前缀[@]的需求,添加了转换参数SQL中的前缀
- 添加DbHelper的简单操作数据库类,核心继承抽象DapperHelperBase
- 添加对Camstar参数SQL前缀(?)的支持
- 处理参数前缀@符号
- 迁移工具库到netstandard2.0,以扩大支持范围
- 解決Db连接执行后一直挂起session的问题
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. 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 is compatible. 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 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 is compatible. net48 is compatible. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.7.2
- Aore.Dapper.Contrib.Lite (>= 1.0.15)
- Dapper (>= 2.1.66)
- Newtonsoft.Json (>= 13.0.3)
- System.Runtime.CompilerServices.Unsafe (>= 6.1.2)
-
.NETFramework 4.8
- Aore.Dapper.Contrib.Lite (>= 1.0.15)
- Dapper (>= 2.1.66)
- Newtonsoft.Json (>= 13.0.3)
- System.Runtime.CompilerServices.Unsafe (>= 6.1.2)
-
.NETStandard 2.0
- Aore.Dapper.Contrib.Lite (>= 1.0.15)
- Dapper (>= 2.1.66)
- Newtonsoft.Json (>= 13.0.3)
- System.Runtime.CompilerServices.Unsafe (>= 6.1.2)
-
net6.0
- Aore.Dapper.Contrib.Lite (>= 1.0.15)
- Dapper (>= 2.1.66)
- Newtonsoft.Json (>= 13.0.3)
-
net7.0
- Aore.Dapper.Contrib.Lite (>= 1.0.15)
- Dapper (>= 2.1.66)
- Newtonsoft.Json (>= 13.0.3)
-
net8.0
- Aore.Dapper.Contrib.Lite (>= 1.0.15)
- Dapper (>= 2.1.66)
- Newtonsoft.Json (>= 13.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.
一个基于 .NET Standard 2.0 和Dapper的数据库操作工具库,提供了多种数据访问和实用功能的支持