Skip to content

Class DbHelperExensions

Namespace: Tool.SqlCore
Assembly: Tool.Net.dll

对象,提供扩展支持

csharp
public static class DbHelperExensions

Inheritance

objectDbHelperExensions

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Extension Methods

ObjectExtension.Add<T>(object, object, object), ObjectExtension.CopyEntity(object, object, params string[]), ObjectExtension.EntityToJson(object), ObjectExtension.EntityToJson(object, bool), ObjectExtension.EntityToJson(object, bool, string), DictionaryExtension.GetDictionary(object), TypeExtension.GetFieldKey(object, string, out bool), TypeExtension.GetFieldKey<T>(object, string, out bool), TypeExtension.GetFieldKey(object, Type, string, out bool), ObjectExtension.GetIntPtr(object), ObjectExtension.GetIntPtrInt(object), TypeExtension.GetPropertieFind(object, string, bool), TypeExtension.GetProperties(object), TypeExtension.GetPropertyKey(object, string, out bool), TypeExtension.GetPropertyKey<T>(object, string, out bool), TypeExtension.GetPropertyKey(object, Type, string, out bool), TypeExtension.GetValue(object, PropertyDescriptor), TypeExtension.GetValue(object, string, bool), TypeExtension.GetValue(object, string), ObjectExtension.Read<T>(object, object, int, int), ObjectExtension.Read<T>(object, int, object, int, int), DictionaryExtension.SetDictionary(object, IDictionary<string, object>), TypeExtension.SetFieldKey(object, string, object), TypeExtension.SetFieldKey<T>(object, string, object), TypeExtension.SetFieldKey(object, Type, string, object), TypeExtension.SetPropertyKey(object, string, object), TypeExtension.SetPropertyKey<T>(object, string, object), TypeExtension.SetPropertyKey(object, Type, string, object), TypeExtension.SetValue(object, PropertyDescriptor, object), TypeExtension.SetValue(object, string, object, bool), TypeExtension.SetValue(object, string, object), ObjectExtension.ToBase64String(object), ObjectExtension.ToBytes(object), ObjectExtension.ToBytes(object, out Type), DictionaryExtension.ToDictionary(object), DictionaryExtension.ToDictionary<T>(object), DictionaryExtension.ToIDictionary(object), DictionaryExtension.ToIDictionary<T>(object), ObjectExtension.ToJson(object), ObjectExtension.ToJson(object, JsonSerializerOptions), ObjectExtension.ToJsonWeb(object), ObjectExtension.ToJsonWeb(object, Action<JsonSerializerOptions>), ObjectExtension.ToTryVar<T>(object, T), ObjectExtension.ToVar<T>(object), ObjectExtension.ToVar(object, Type, bool), ObjectExtension.ToVar(object, string), ObjectExtension.ToXml(object)

Remarks

代码由逆血提供支持

Methods

Delete<T>(DbHelper, string, object)

删除单张表数据

csharp
public static int Delete<T>(this DbHelper dbHelper, string where, object prams) where T : new()

Parameters

dbHelper DbHelper

数据库引擎

where string

删除的条件

prams object

删除条件的参数,可以是任何类型的键值对

Returns

int

Type Parameters

T

Delete(DbHelper, string, string, object)

删除单张表数据

csharp
public static int Delete(this DbHelper dbHelper, string TableName, string where, object prams)

Parameters

dbHelper DbHelper

数据库引擎

TableName string

表名

where string

删除的条件

prams object

删除条件的参数,可以是任何类型的键值对

Returns

int

Delete(DbHelper, params string[])

删除多多张表数据

csharp
public static int Delete(this DbHelper dbHelper, params string[] commandTexts)

Parameters

dbHelper DbHelper

数据库引擎

commandTexts string[]

多张表删除语句

Returns

int

DeleteAsync<T>(DbHelper, string, object)

删除单张表数据

csharp
public static Task<int> DeleteAsync<T>(this DbHelper dbHelper, string where, object prams) where T : new()

Parameters

dbHelper DbHelper

数据库引擎

where string

删除的条件

prams object

删除条件的参数,可以是任何类型的键值对

Returns

Task<int>

Type Parameters

T

DeleteAsync(DbHelper, string, string, object)

删除单张表数据

csharp
public static Task<int> DeleteAsync(this DbHelper dbHelper, string TableName, string where, object prams)

Parameters

dbHelper DbHelper

数据库引擎

TableName string

表名

where string

删除的条件

prams object

删除条件的参数,可以是任何类型的键值对

Returns

Task<int>

DeleteAsync(DbHelper, params string[])

删除多多张表数据

csharp
public static Task<int> DeleteAsync(this DbHelper dbHelper, params string[] commandTexts)

Parameters

dbHelper DbHelper

数据库引擎

commandTexts string[]

多张表删除语句

Returns

Task<int>

GetDataColumnSchema(DbDataReader)

获取DataTable表信息不含数据

csharp
public static DataTable GetDataColumnSchema(this DbDataReader dataReader)

Parameters

dataReader DbDataReader

原数据对象

Returns

DataTable

GetDataColumnSchemaAsync(DbDataReader)

获取DataTable表信息不含数据

csharp
public static Task<DataTable> GetDataColumnSchemaAsync(this DbDataReader dataReader)

Parameters

dataReader DbDataReader

原数据对象

Returns

Task<DataTable>

GetDataSet(DbDataReader)

对象,中数据转换为

csharp
public static DataSet GetDataSet(this DbDataReader dataReader)

Parameters

dataReader DbDataReader

原数据对象

Returns

DataSet

返回可读集合字典

GetDataSetAsync(DbDataReader)

对象,中数据转换为

csharp
public static Task<DataSet> GetDataSetAsync(this DbDataReader dataReader)

Parameters

dataReader DbDataReader

原数据对象

Returns

Task<DataSet>

返回可读集合字典

GetDataTable(DbDataReader)

对象,中数据转换为

csharp
public static DataTable GetDataTable(this DbDataReader dataReader)

Parameters

dataReader DbDataReader

原数据对象

Returns

DataTable

返回可读集合字典

GetDataTableAsync(DbDataReader)

对象,中数据转换为

csharp
public static Task<DataTable> GetDataTableAsync(this DbDataReader dataReader)

Parameters

dataReader DbDataReader

原数据对象

Returns

Task<DataTable>

返回可读集合字典

GetInsertParams(DbHelper, IDictionary<string, object>, out string, out string)

根据键值对生成 Insert 部分语法,和值添加对象

csharp
public static List<DbParameter> GetInsertParams(this DbHelper database, IDictionary<string, object> keyValues, out string key, out string value)

Parameters

database DbHelper

数据库引擎

keyValues IDictionary<string, object>

数据集键值对

key string

返回生成的部分SQL语句

value string

返回生成的部分SQL语句

Returns

List<DbParameter>

GetListHash(DbDataReader, bool)

对象,中数据转换为集合字典

csharp
public static IList<IDictionary<string, object>> GetListHash(this DbDataReader dataReader, bool isnull = false)

Parameters

dataReader DbDataReader

原数据对象

isnull bool

是否处理Null值,true时将不包含在字典中

Returns

IList<IDictionary<string, object>>

返回可读集合字典

GetListHashAsync(DbDataReader, bool)

对象,中数据转换为集合字典

csharp
public static Task<IList<IDictionary<string, object>>> GetListHashAsync(this DbDataReader dataReader, bool isnull = false)

Parameters

dataReader DbDataReader

原数据对象

isnull bool

是否处理Null值,true时将不包含在字典中

Returns

Task<IList<IDictionary<string, object>>>

返回可读集合字典

GetReader<T>()

一个测试阶段的 实体转换函数

csharp
public static Func<DbDataReader, T> GetReader<T>()

Returns

Func<DbDataReader, T>

Type Parameters

T

GetReaderArray(DbDataReader, bool)

对象,中数据转换为 二维数组集合

csharp
public static ArrayList GetReaderArray(this DbDataReader dataReader, bool isnull = false)

Parameters

dataReader DbDataReader

原数据对象

isnull bool

是否处理Null值,true时将不包含在二维数组中

Returns

ArrayList

返回可读二维数组集合

GetReaderArrayAsync(DbDataReader, bool)

对象,中数据转换为 二维数组集合

csharp
public static Task<ArrayList> GetReaderArrayAsync(this DbDataReader dataReader, bool isnull = false)

Parameters

dataReader DbDataReader

原数据对象

isnull bool

是否处理Null值,true时将不包含在二维数组中

Returns

Task<ArrayList>

返回可读二维数组集合

GetTextParameter(DbHelper, string, object)

提供快捷方式,匿名对象实现

csharp
public static SqlTextParameter GetTextParameter(this DbHelper dbHelper, string commandText, object prams)

Parameters

dbHelper DbHelper

数据库引擎

commandText string

执行的SQL语句

prams object

携带的参数可以是Null,可以是任何类型的键值对

Returns

SqlTextParameter

返回对象

GetUpdateParams(DbHelper, IDictionary<string, object>, out string)

根据键值对生成 Update 部分语法,和值添加对象

csharp
public static List<DbParameter> GetUpdateParams(this DbHelper database, IDictionary<string, object> keyValues, out string strsql)

Parameters

database DbHelper

数据库引擎

keyValues IDictionary<string, object>

数据集键值对

strsql string

返回生成的部分SQL语句

Returns

List<DbParameter>

Insert<T>(DbHelper, object)

插入一条结果

csharp
public static int Insert<T>(this DbHelper dbHelper, object prams) where T : new()

Parameters

dbHelper DbHelper

数据库引擎

prams object

实体类,虚构对象,任何类型的键值对

Returns

int

Type Parameters

T

Insert(DbHelper, string, object)

插入一条结果

csharp
public static int Insert(this DbHelper dbHelper, string TableName, object prams)

Parameters

dbHelper DbHelper

数据库引擎

TableName string

表名

prams object

实体类,虚构对象,任何类型的键值对

Returns

int

Insert(DbHelper, params string[])

插入多条结果,可以是多张不同的表

csharp
public static int Insert(this DbHelper dbHelper, params string[] commandTexts)

Parameters

dbHelper DbHelper

数据库引擎

commandTexts string[]

多条插入语句

Returns

int

InsertAsync<T>(DbHelper, object)

插入一条结果

csharp
public static Task<int> InsertAsync<T>(this DbHelper dbHelper, object prams) where T : new()

Parameters

dbHelper DbHelper

数据库引擎

prams object

实体类,虚构对象,任何类型的键值对

Returns

Task<int>

Type Parameters

T

InsertAsync(DbHelper, string, object)

插入一条结果

csharp
public static Task<int> InsertAsync(this DbHelper dbHelper, string TableName, object prams)

Parameters

dbHelper DbHelper

数据库引擎

TableName string

表名

prams object

实体类,虚构对象,任何类型的键值对

Returns

Task<int>

InsertAsync(DbHelper, params string[])

插入多条结果,可以是多张不同的表

csharp
public static Task<int> InsertAsync(this DbHelper dbHelper, params string[] commandTexts)

Parameters

dbHelper DbHelper

数据库引擎

commandTexts string[]

多条插入语句

Returns

Task<int>

Select(DbHelper, string, object)

查询单张表

csharp
public static DataTable Select(this DbHelper dbHelper, string commandText, object prams = null)

Parameters

dbHelper DbHelper

数据库引擎

commandText string

查询语句

prams object

实体类,虚构对象,任何类型的键值对

Returns

DataTable

Select<T>(DbHelper, Action<T>)

查询单张表

csharp
public static IList<T> Select<T>(this DbHelper dbHelper, Action<T> prams = null) where T : new()

Parameters

dbHelper DbHelper

数据库引擎

prams Action<T>

查询条件

Returns

IList<T>

Type Parameters

T

Select(DbHelper, params string[])

查询多张表

csharp
public static DataSet Select(this DbHelper dbHelper, params string[] commandTexts)

Parameters

dbHelper DbHelper

数据库引擎

commandTexts string[]

多条查询语句

Returns

DataSet

SelectArray(DbHelper, string, object)

查询单张表

csharp
public static ArrayList SelectArray(this DbHelper dbHelper, string commandText, object prams = null)

Parameters

dbHelper DbHelper

数据库引擎

commandText string

查询语句

prams object

实体类,虚构对象,任何类型的键值对

Returns

ArrayList

SelectArray(DbHelper, CommandType, string, object)

查询单张表

csharp
public static ArrayList SelectArray(this DbHelper dbHelper, CommandType command, string commandText, object prams = null)

Parameters

dbHelper DbHelper

数据库引擎

command CommandType

执行模式

commandText string

查询语句

prams object

实体类,虚构对象,任何类型的键值对

Returns

ArrayList

SelectArrayAsync(DbHelper, string, object)

查询单张表

csharp
public static Task<ArrayList> SelectArrayAsync(this DbHelper dbHelper, string commandText, object prams = null)

Parameters

dbHelper DbHelper

数据库引擎

commandText string

查询语句

prams object

实体类,虚构对象,任何类型的键值对

Returns

Task<ArrayList>

SelectArrayAsync(DbHelper, CommandType, string, object)

查询单张表

csharp
public static Task<ArrayList> SelectArrayAsync(this DbHelper dbHelper, CommandType command, string commandText, object prams = null)

Parameters

dbHelper DbHelper

数据库引擎

command CommandType

执行模式

commandText string

查询语句

prams object

实体类,虚构对象,任何类型的键值对

Returns

Task<ArrayList>

SelectAsync(DbHelper, string, object)

查询单张表

csharp
public static Task<DataTable> SelectAsync(this DbHelper dbHelper, string commandText, object prams = null)

Parameters

dbHelper DbHelper

数据库引擎

commandText string

查询语句

prams object

实体类,虚构对象,任何类型的键值对

Returns

Task<DataTable>

SelectAsync<T>(DbHelper, Action<T>)

查询单张表

csharp
public static Task<IList<T>> SelectAsync<T>(this DbHelper dbHelper, Action<T> prams = null) where T : new()

Parameters

dbHelper DbHelper

数据库引擎

prams Action<T>

查询条件

Returns

Task<IList<T>>

Type Parameters

T

SelectAsync(DbHelper, params string[])

查询多张表

csharp
public static Task<DataSet> SelectAsync(this DbHelper dbHelper, params string[] commandTexts)

Parameters

dbHelper DbHelper

数据库引擎

commandTexts string[]

多条查询语句

Returns

Task<DataSet>

SelectDictionary(DbHelper, string, object)

查询单张表

csharp
public static IList<IDictionary<string, object>> SelectDictionary(this DbHelper dbHelper, string commandText, object prams = null)

Parameters

dbHelper DbHelper

数据库引擎

commandText string

查询语句

prams object

实体类,虚构对象,任何类型的键值对

Returns

IList<IDictionary<string, object>>

SelectDictionary(DbHelper, CommandType, string, object)

查询单张表

csharp
public static IList<IDictionary<string, object>> SelectDictionary(this DbHelper dbHelper, CommandType command, string commandText, object prams = null)

Parameters

dbHelper DbHelper

数据库引擎

command CommandType

执行模式

commandText string

查询语句

prams object

实体类,虚构对象,任何类型的键值对

Returns

IList<IDictionary<string, object>>

SelectDictionaryAsync(DbHelper, string, object)

查询单张表

csharp
public static Task<IList<IDictionary<string, object>>> SelectDictionaryAsync(this DbHelper dbHelper, string commandText, object prams = null)

Parameters

dbHelper DbHelper

数据库引擎

commandText string

查询语句

prams object

实体类,虚构对象,任何类型的键值对

Returns

Task<IList<IDictionary<string, object>>>

SelectDictionaryAsync(DbHelper, CommandType, string, object)

查询单张表

csharp
public static Task<IList<IDictionary<string, object>>> SelectDictionaryAsync(this DbHelper dbHelper, CommandType command, string commandText, object prams = null)

Parameters

dbHelper DbHelper

数据库引擎

command CommandType

执行模式

commandText string

查询语句

prams object

实体类,虚构对象,任何类型的键值对

Returns

Task<IList<IDictionary<string, object>>>

Update<T>(DbHelper, string, params object[])

修改单表结果

csharp
public static int Update<T>(this DbHelper dbHelper, string where, params object[] prams) where T : new()

Parameters

dbHelper DbHelper

数据库引擎

where string

修改的条件

prams object[]

修改表的参数 Or 修改条件的参数,可以是任何类型的键值对

Returns

int

Type Parameters

T

Update(DbHelper, string, string, params object[])

修改单表结果

csharp
public static int Update(this DbHelper dbHelper, string TableName, string where, params object[] prams)

Parameters

dbHelper DbHelper

数据库引擎

TableName string

表名

where string

修改的条件,无需写 WHERE 直接条件

prams object[]

修改表的参数 Or 修改条件的参数,可以是任何类型的键值对

Returns

int

Update(DbHelper, params string[])

修改多表结果

csharp
public static int Update(this DbHelper dbHelper, params string[] commandTexts)

Parameters

dbHelper DbHelper

数据库引擎

commandTexts string[]

多条插入语句

Returns

int

UpdateAsync<T>(DbHelper, string, params object[])

修改单表结果

csharp
public static Task<int> UpdateAsync<T>(this DbHelper dbHelper, string where, params object[] prams) where T : new()

Parameters

dbHelper DbHelper

数据库引擎

where string

修改的条件

prams object[]

修改表的参数 Or 修改条件的参数,可以是任何类型的键值对

Returns

Task<int>

Type Parameters

T

UpdateAsync(DbHelper, string, string, params object[])

修改单表结果

csharp
public static Task<int> UpdateAsync(this DbHelper dbHelper, string TableName, string where, params object[] prams)

Parameters

dbHelper DbHelper

数据库引擎

TableName string

表名

where string

修改的条件,无需写 WHERE 直接条件

prams object[]

修改表的参数 Or 修改条件的参数,可以是任何类型的键值对

Returns

Task<int>

UpdateAsync(DbHelper, params string[])

修改多表结果

csharp
public static Task<int> UpdateAsync(this DbHelper dbHelper, params string[] commandTexts)

Parameters

dbHelper DbHelper

数据库引擎

commandTexts string[]

多条插入语句

Returns

Task<int>

WhereStr(string)

避免问题where 第一位不能为空格

csharp
public static string WhereStr(string where)

Parameters

where string

Returns

string

基于Apache-2.0协议开源