CoreDBHelper 1.0.8

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

.NET 使用正则表达式,xml解析,封装 Dapper 让SQL从代码迁移到xml文件上,并实现简单的逻辑处理

使用方法

1.配置连接字符串

.NET 5 引用 CoreDBHelper.dll 在appsettings.json中增加 "ConnectionStrings": { "test_mysql": "server=127.0.0.1;userid=;pwd=;port=3306;database=****;sslmode=none;" } 然后在Startup.cs的ConfigureServices中通过代码附加连接字符串 SQLHelperFactory.Instance.ConnectionStringsDic["test_mysql"] = Configuration.GetConnectionString("test_mysql");

2.配置SQL语句 在项目上增加文件夹SqlConfig,增加DemoSql.xml文件

xml内容如下:

<?xml version="1.0" encoding="utf-8" ?> <SqlSetting> <Data name="SelectTable"> <SqlDefinition type="MySql" ConnStringName="test_mysql"> <SqlCommand> <![CDATA[ SELECT * FROM table where age = @@age@@ <%= name like CONCAT('%',@@name@@,'%') %> <R%= @@startIndex@@, @@selectCount@@ %R> ]]> </SqlCommand> </SqlDefinition> </Data> </SqlSetting>

using DBHelper.SQLHelper; using System; using System.Collections.Generic;

namespace CoreDBDemo { class Program { static void Main(string[] args) { Dictionary<string, object> paramDic = new Dictionary<string, object>(); paramDic["age"] = 18; paramDic["name"] = "admin"; paramDic["startIndex"] = 0; paramDic["selectCount"] = 10; var list = SQLHelperFactory.Instance.QueryForList("SelectTable", paramDic); Console.Read(); } } } // 此时生成的SQL为: SELECT * FROM table where age = ?age name like CONCAT('%',?name,'%') 0, 10

using DBHelper.SQLHelper; using System; using System.Collections.Generic;

namespace CoreDBDemo { class Program { static void Main(string[] args) { Dictionary<string, object> paramDic = new Dictionary<string, object>(); paramDic["age"] = 18; paramDic["name"] = "admin"; paramDic["startIndex"] = 0; //paramDic["selectCount"] = 10; var list = SQLHelperFactory.Instance.QueryForList("SelectTable", paramDic); Console.Read(); } } } // 此时生成的SQL为: SELECT * FROM table where age = ?age name like CONCAT('%',?name,'%')

using DBHelper.SQLHelper; using System; using System.Collections.Generic;

namespace CoreDBDemo { class Program { static void Main(string[] args) { Dictionary<string, object> paramDic = new Dictionary<string, object>(); paramDic["age"] = 18; //paramDic["name"] = "admin"; paramDic["startIndex"] = 0; //paramDic["selectCount"] = 10; var list = SQLHelperFactory.Instance.QueryForList("SelectTable", paramDic); Console.Read(); } } } // 此时生成的SQL为: SELECT * FROM table where age = ?age

4.接口说明

// 返回影响行数 public int ExecuteNonQuery(string sqlKey, Dictionary<string, object> paramDic, bool isUseTrans = false, int maxretry = MaxRetry);

// 返回一条数据 public IDataReader ExecuteReader(string sqlKey, Dictionary<string, object> paramDic, bool isUseTrans = false, int maxretry = MaxRetry)

// 返回第一行第一列 public object ExecuteScalar(string sqlKey, Dictionary<string, object> paramDic, bool isUseTrans = false, int maxretry = MaxRetry)

// 返回第一行第一列 public T ExecuteScalarByT(string sqlKey, Dictionary<string, object> paramDic, bool isUseTrans = false, int maxretry = MaxRetry)

// 返回IEnumerable public List QueryForList(string sqlKey, Dictionary<string, object> paramDic, bool isUseTrans = false, int maxretry = MaxRetry)

// 返回IEnumerable public List QueryForListByT(string sqlKey, Dictionary<string, object> paramDic, bool isUseTrans = false, int maxretry = MaxRetry)

// 通过sql配置控制返回的类型,调用 QueryForListByT public List QueryForLisByAssembly(string sqlKey, Dictionary<string, object> paramDic, bool isUseTrans = false, int maxretry = MaxRetry)

// 返回dynamic public dynamic QueryForObject(string sqlKey, Dictionary<string, object> paramDic, bool isUseTrans = false, int maxretry = MaxRetry)

// 返回T public T QueryForObjectByT(string sqlKey, Dictionary<string, object> paramDic, bool isUseTrans = false, int maxretry = MaxRetry)

// 返回结果集和数量 专为分页功能而准备 数据集的sql在前面,返回数量的在后面 public IEnumerable QueryMultipleByPage(string sqlKey, Dictionary<string, object> paramDic, out int total, bool isUseTrans = false, int maxretry = MaxRetry)

// 返回多个结果集 public IEnumerable QueryMultiple<TFirst, TSecond, TReturn>(string sqlKey, Dictionary<string, object> paramDic, Func<IEnumerable, IEnumerable, IEnumerable> func, bool isUseTrans = false, int maxretry = MaxRetry)

具体参考 CoreDBDemo

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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. 
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.0.8 160 2/28/2024
1.0.7 450 6/10/2021
1.0.6 652 1/10/2020
1.0.5 593 1/9/2020
1.0.4 683 5/23/2019
1.0.3 694 5/22/2019
1.0.2 785 1/9/2019
1.0.1 1,225 6/11/2018
1.0.0 1,231 6/11/2018

1. 增加直接执行SQL语句的支持;2. 增加TimeOut时间控制;3. 增加父节点配置;4. 增加测试连接方法;5. 增加外部开启事务支持;