Aore.DapperHelper 1.8.2

dotnet add package Aore.DapperHelper --version 1.8.2
                    
NuGet\Install-Package Aore.DapperHelper -Version 1.8.2
                    
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="Aore.DapperHelper" Version="1.8.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Aore.DapperHelper" Version="1.8.2" />
                    
Directory.Packages.props
<PackageReference Include="Aore.DapperHelper" />
                    
Project file
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 Aore.DapperHelper --version 1.8.2
                    
#r "nuget: Aore.DapperHelper, 1.8.2"
                    
#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 Aore.DapperHelper@1.8.2
                    
#: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=Aore.DapperHelper&version=1.8.2
                    
Install as a Cake Addin
#tool nuget:?package=Aore.DapperHelper&version=1.8.2
                    
Install as a Cake Tool

Aore.DapperHelper — .NET SDK

Static Badge license

[English Version]

📈 一个基于 .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 列表(使用事务)
  • BatchExecutionForeachNTS(重载参数): 批量执行 SQL 列表(无事务)
  • BatchExecutionBeginEndNTS(重载参数): 使用 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);

// ...

📢 更新记录

  • 数据效能优化,修改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的问题

✋ 贡献代码

如果需要使用或修改此项目的源代码,建议先Fork。也欢迎将您修改的通用版本Pull Request过来。

  1. Fork
  2. 创建您的特性分支 (git checkout -b my-new-feature)
  3. 提交您的改动 (git commit -am 'Added some feature')
  4. 将您的修改记录提交到远程 git 仓库 (git push origin my-new-feature)
  5. 然后到 github 网站的该 git 远程仓库的 my-new-feature 分支下发起 Pull Request (请提交到 Developer 分支,不要直接提交到 master 分支)
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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.  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 was computed.  net48 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.8.2 130 12/30/2025
1.8.1 139 10/4/2025
1.0.0 399 7/25/2025

一个基于 .NET Standard 2.0 和Dapper的数据库操作工具库,提供了多种数据访问和实用功能的支持