Nuget调用简单封装.
1. 项目引用Dapper作为直接访问, 为了使用方便, 封装一下.达到效果:
- 数据库连接配置在webconfig.xml中.
- 常用调用方法封装.
调用: //可以采用单例模式.
//全局实例
public static DapperEntity DBI
{
get
{
return DapperEntity.Instance;
}
}
//调用
public static DateTime GetDBDateTime()
{
return DBI.QueryFirst<DateTime>("SELECT GETDATE()");
}
参考单例:
private static object syncObj = new object();
private static DapperEntity instance;
public static DapperEntity Instance
{
get
{
if (instance == null)
{
lock (syncObj)
{
if (instance == null)
{
instance = DapperEntity.Instance
}
}
}
return instance;
}
}
封装类:
<add key="TSQLConnectionString" value=""/> //配置在webconfig.xml中
public class DapperEntity
{
private static DapperEntity instance;
private string ConnectionString;
private IDbConnection DefineConnection;
private IDbConnection DefaultConnection;
private IDbTransaction Transaction;
public static DapperEntity Instance
{
get
{
return new DapperEntity("");
}
}
public IDbConnection Connection
{
get
{
IDbConnection result;
if (this.DefineConnection != null)
{
result = this.DefineConnection;
}
else
{
if (this.DefaultConnection == null)
{
this.DefaultConnection = new SqlConnection(this.ConnectionString);
}
result = this.DefaultConnection;
}
return result;
}
}
public DapperEntity(string connectionStr = "")
{
if (string.IsNullOrEmpty(connectionStr))
{
connectionStr = ConfigurationManager.ConnectionStrings["TSQLDBConnectionString"].ConnectionString;
}
this.ConnectionString = connectionStr;
}
public DapperEntity(IDbConnection connection)
{
this.DefineConnection = connection;
}
public DataBaseType GetDataBaseType()
{
string name = this.Connection.GetType().Name;
string text = name;
DataBaseType result;
if (text != null)
{
if (text == "SQLiteConnection")
{
result = DataBaseType.SQLiteConnection;
return result;
}
if (!(text == "SqlConnection"))
{
}
}
result = DataBaseType.SqlConnection;
return result;
}
}
完整包括方法如下:
public class DapperEntity
{
private static DapperEntity instance;
private string ConnectionString;
private IDbConnection DefineConnection;
private IDbConnection DefaultConnection;
private IDbTransaction Transaction;
public static DapperEntity Instance
{
get
{
return new DapperEntity("");
}
}
public IDbConnection Connection
{
get
{
IDbConnection result;
if (this.DefineConnection != null)
{
result = this.DefineConnection;
}
else
{
if (this.DefaultConnection == null)
{
this.DefaultConnection = new SqlConnection(this.ConnectionString);
}
result = this.DefaultConnection;
}
return result;
}
}
public DapperEntity(string connectionStr = "")
{
if (string.IsNullOrEmpty(connectionStr))
{
connectionStr = ConfigurationManager.ConnectionStrings["TSQLDBConnectionString"].ConnectionString;
}
this.ConnectionString = connectionStr;
}
public DapperEntity(IDbConnection connection)
{
this.DefineConnection = connection;
}
public DataBaseType GetDataBaseType()
{
string name = this.Connection.GetType().Name;
string text = name;
DataBaseType result;
if (text != null)
{
if (text == "SQLiteConnection")
{
result = DataBaseType.SQLiteConnection;
return result;
}
if (!(text == "SqlConnection"))
{
}
}
result = DataBaseType.SqlConnection;
return result;
}
public object GetArrayFirst(object param)
{
object result;
if (param.GetType().BaseType.Name == "Array")
{
object[] array = param as object[];
if (array.Length == 0)
{
throw new Exception("数组不能为空");
}
result = array[0];
}
else
{
result = null;
}
return result;
}
private string BindQueryPageSql(string sql, PageQueryParams pqp)
{
int num = (pqp.PageIndex - 1) * pqp.PageSize;
int num2 = num + pqp.PageSize;
return string.Concat(new object[]
{
"select * from (select row_number()over(order by ",
pqp.OrderField,
" ",
pqp.OrderDirection.ToString(),
")rownumber,* from (",
sql,
")t1)t2 WHERE rownumber>",
num,
" and rownumber<=",
num2
});
}
public PageQueryModel<T> OQueryPage<T>(PageQueryParams pageQueryParams, string sql, object param = null, IDbTransaction transaction = null, bool buffered = true, int? commandTimeout = null, CommandType? commandType = null)
{
int total = Convert.ToInt32(this.Connection.ExecuteScalar("select count(*) from (" + sql + ")a", param, transaction, commandTimeout, commandType));
sql = this.BindQueryPageSql(sql, pageQueryParams);
return new PageQueryModel<T>
{
Total = total,
Data = this.Connection.Query(sql, param, transaction, buffered, commandTimeout, commandType)
};
}
[return: Dynamic(new bool[]
{
false,
true
})]
public PageQueryModel<dynamic> OQueryPage(PageQueryParams pageQueryParams, string sql, object param = null, IDbTransaction transaction = null, bool buffered = true, int? commandTimeout = null, CommandType? commandType = null)
{
int total = Convert.ToInt32(this.Connection.ExecuteScalar("select count(*) from (" + sql + ")a", param, transaction, commandTimeout, commandType));
sql = this.BindQueryPageSql(sql, pageQueryParams);
return new PageQueryModel<object>
{
Total = total,
Data = this.Connection.Query(sql, param, transaction, buffered, commandTimeout, commandType)
};
}
[return: Dynamic]
public dynamic OQueryFirstByPrimaryKey(object param, string tableName = null, string primaryKey = null, IDbTransaction transaction = null, int? commandTimeout = null)
{
ObjectParser objectParser = ObjectParser.Bulid(param, tableName, primaryKey, true);
return this.QueryFirstOrDefault(string.Concat(new string[]
{
"select * from ",
objectParser.TableName,
" where ",
objectParser.PrimaryPropertyInfo.Name,
"=@",
objectParser.PrimaryPropertyInfo.Name
}), param, transaction, commandTimeout, null);
}
public T OQueryFirstByPrimaryKey<T>(object param, string primaryKey = null, IDbTransaction transaction = null, int? commandTimeout = null)
{
ObjectParser objectParser = ObjectParser.Bulid<T>(param, primaryKey, true);
return this.QueryFirstOrDefault<T>(string.Concat(new string[]
{
"select * from ",
objectParser.TableName,
" where ",
objectParser.PrimaryPropertyInfo.Name,
"=@",
objectParser.PrimaryPropertyInfo.Name
}), param, transaction, commandTimeout, null);
}
[return: Dynamic(new bool[]
{
false,
true
})]
public IEnumerable<dynamic> OQuery(object param, string where = null, string tableName = null, IDbTransaction transaction = null)
{
ObjectParser objectParser = ObjectParser.Bulid(param, tableName, null, false);
return this.Query("select * from " + objectParser.TableName + ((!string.IsNullOrEmpty(where)) ? (" where " + where) : ""), param, transaction, true, null, null);
}
public IEnumerable<T> OQuery<T>(object param, string where = null, IDbTransaction transaction = null, int? commandTimeout = null)
{
ObjectParser objectParser = ObjectParser.Bulid<T>(param, null, false);
return this.Query<T>("select * from " + objectParser.TableName + ((!string.IsNullOrEmpty(where)) ? (" where " + where) : ""), param, transaction, true, null, null);
}
[return: Dynamic]
public dynamic OQueryFirstOrDefault(object param, string where = null, string tableName = null, IDbTransaction transaction = null)
{
ObjectParser objectParser = ObjectParser.Bulid(param, tableName, null, false);
return this.QueryFirstOrDefault("select * from " + objectParser.TableName + ((!string.IsNullOrEmpty(where)) ? (" where " + where) : ""), param, transaction, null, null);
}
public T OQueryFirstOrDefault<T>(object param, string where = null, IDbTransaction transaction = null, int? commandTimeout = null)
{
ObjectParser objectParser = ObjectParser.Bulid<T>(param, null, false);
return this.QueryFirstOrDefault<T>("select * from " + objectParser.TableName + ((!string.IsNullOrEmpty(where)) ? (" where " + where) : ""), param, transaction, null, null);
}
public void BeginTransaction()
{
this.Connection.Open();
this.Transaction = this.Connection.BeginTransaction();
}
public void CommitTransaction()
{
this.Transaction.Commit();
this.Connection.Close();
}
public void RollbackTransaction()
{
this.Transaction.Rollback();
this.Connection.Close();
}
public int OInsert(object param, string tableName = null, IDbTransaction transaction = null, int? commandTimeout = null)
{
ObjectParser oParser = ObjectParser.Bulid(this.GetArrayFirst(param) ?? param, tableName, null, false);
return this.OInsertHandle(param, transaction ?? this.Transaction, commandTimeout, oParser);
}
public int OInsert<T>(object param, IDbTransaction transaction = null, int? commandTimeout = null)
{
ObjectParser oParser = ObjectParser.Bulid<T>(this.GetArrayFirst(param) ?? param, null, false);
return this.OInsertHandle(param, transaction, commandTimeout, oParser);
}
private int OInsertHandle(object param, IDbTransaction transaction, int? commandTimeout, ObjectParser oParser)
{
return this.Execute(string.Concat(new string[]
{
"insert into ",
oParser.TableName,
"(",
oParser.GetSQL_InsertField(),
") values (",
oParser.GetSQL_InsertValue(),
")"
}), param, transaction, commandTimeout, null);
}
public int OUpdate(object param, string whereSql, object whereParam, string tableName = null, IDbTransaction transaction = null, int? commandTimeout = null)
{
ObjectParser objectParser = ObjectParser.Bulid(param, tableName, null, false);
return this.Execute(string.Concat(new string[]
{
"update ",
objectParser.TableName,
" set ",
objectParser.GetSQL_UpdateFieldValue("", null),
" where ",
whereSql
}), param, transaction, commandTimeout, null);
}
public int OUpdateByPrimaryKey(object param, string tableName = null, string primaryKey = null, IDbTransaction transaction = null, int? commandTimeout = null)
{
ObjectParser oParser = ObjectParser.Bulid(this.GetArrayFirst(param) ?? param, tableName, primaryKey, true);
return this.OUpdateByPrimaryKeyHandle(param, transaction, commandTimeout, oParser);
}
public int OUpdateByPrimaryKey<T>(object param, string primaryKey = null, IDbTransaction transaction = null, int? commandTimeout = null)
{
ObjectParser oParser = ObjectParser.Bulid<T>(this.GetArrayFirst(param) ?? param, primaryKey, true);
return this.OUpdateByPrimaryKeyHandle(param, transaction, commandTimeout, oParser);
}
private int OUpdateByPrimaryKeyHandle(object param, IDbTransaction transaction, int? commandTimeout, ObjectParser oParser)
{
return this.Execute(string.Concat(new string[]
{
"update ",
oParser.TableName,
" set ",
oParser.GetSQL_UpdateFieldValue("", null),
" where ",
oParser.PrimaryPropertyInfo.Name,
"=@",
oParser.PrimaryPropertyInfo.Name
}), param, transaction, commandTimeout, null);
}
public int OUpdate(object param, string where, string tableName = null, IDbTransaction transaction = null, int? commandTimeout = null)
{
ObjectParser oParser = ObjectParser.Bulid(this.GetArrayFirst(param) ?? param, tableName, null, false);
return this.OUpdateHandle(param, where, transaction, commandTimeout, oParser);
}
private int OUpdateHandle(object param, string where, IDbTransaction transaction, int? commandTimeout, ObjectParser oParser)
{
return this.Execute(string.Concat(new string[]
{
"update ",
oParser.TableName,
" set ",
oParser.GetSQL_UpdateFieldValue(where, null),
(!string.IsNullOrEmpty(where)) ? (" where " + where) : ""
}), param, transaction, commandTimeout, null);
}
public int OUpdate<T>(object param, string where, IDbTransaction transaction = null, int? commandTimeout = null)
{
ObjectParser oParser = ObjectParser.Bulid<T>(this.GetArrayFirst(param) ?? param, null, false);
return this.OUpdateHandle(param, where, transaction, commandTimeout, oParser);
}
public int OInsertOrUpdate(object param, string tableName = null, string primaryKey = null, string[] UnUpdateColumns = null, IDbTransaction transaction = null, int? commandTimeout = null)
{
object arrayFirst = this.GetArrayFirst(param);
bool flag = arrayFirst != null;
int result;
if (this.GetDataBaseType() == DataBaseType.SqlConnection)
{
ObjectParser objectParser = ObjectParser.Bulid(arrayFirst ?? param, tableName, primaryKey, true);
result = this.Execute(string.Concat(new string[]
{
"IF Not EXISTS (SELECT * FROM dbo.AppUserConfig WHERE UserID=@UserID) insert into ",
objectParser.TableName,
"(",
objectParser.GetSQL_InsertField(),
") values (",
objectParser.GetSQL_InsertValue(),
")ELSE update ",
objectParser.TableName,
" set ",
objectParser.GetSQL_UpdateFieldValue("", UnUpdateColumns),
" where ",
objectParser.PrimaryPropertyInfo.Name,
"=@",
objectParser.PrimaryPropertyInfo.Name
}), param, transaction, commandTimeout, null);
}
else
{
if (!flag)
{
if (!this.OExistByPrimaryKey(param, tableName, primaryKey, null))
{
result = this.OInsert(param, tableName, transaction, commandTimeout);
}
else
{
result = this.OUpdateByPrimaryKey(param, tableName, primaryKey, transaction, commandTimeout);
}
}
else
{
object[] array = param as object[];
int num = 0;
object[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
object obj = array2[i];
if (!this.OExistByPrimaryKey(param, tableName, primaryKey, null))
{
num += this.OInsert(param, tableName, transaction, commandTimeout);
}
else
{
num += this.OUpdateByPrimaryKey(param, tableName, primaryKey, transaction, commandTimeout);
}
}
result = num;
}
}
return result;
}
public int OInsertOrUpdate<T>(object param, string primaryKey = null, IDbTransaction transaction = null, int? commandTimeout = null)
{
object arrayFirst = this.GetArrayFirst(param);
bool flag = arrayFirst != null;
int result;
if (this.GetDataBaseType() == DataBaseType.SqlConnection)
{
ObjectParser objectParser = ObjectParser.Bulid<T>(arrayFirst ?? param, primaryKey, true);
result = this.Execute(string.Concat(new string[]
{
"IF Not EXISTS (SELECT * FROM dbo.AppUserConfig WHERE UserID=@UserID) insert into ",
objectParser.TableName,
"(",
objectParser.GetSQL_InsertField(),
") values (",
objectParser.GetSQL_InsertValue(),
")ELSE update ",
objectParser.TableName,
" set ",
objectParser.GetSQL_UpdateFieldValue("", null),
" where ",
objectParser.PrimaryPropertyInfo.Name,
"=@",
objectParser.PrimaryPropertyInfo.Name
}), param, transaction, commandTimeout, null);
}
else
{
if (!flag)
{
if (!this.OExistByPrimaryKey<T>(param, primaryKey, null))
{
result = this.OInsert<T>(param, transaction, commandTimeout);
}
else
{
result = this.OUpdateByPrimaryKey<T>(param, primaryKey, transaction, commandTimeout);
}
}
else
{
object[] array = param as object[];
int num = 0;
object[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
object obj = array2[i];
if (!this.OExistByPrimaryKey<T>(param, primaryKey, null))
{
num += this.OInsert<T>(param, transaction, commandTimeout);
}
else
{
num += this.OUpdateByPrimaryKey<T>(param, primaryKey, transaction, commandTimeout);
}
}
result = num;
}
}
return result;
}
public bool OExistByPrimaryKey(object param, string tableName = null, string primaryKey = null, int? commandTimeout = null)
{
ObjectParser oParser = ObjectParser.Bulid(param, tableName, primaryKey, true);
return this.OExistByPrimaryKeyHandle(param, oParser);
}
public bool OExistByPrimaryKey<T>(object param, string primaryKey = null, int? commandTimeout = null)
{
ObjectParser oParser = ObjectParser.Bulid<T>(this.GetArrayFirst(param) ?? param, primaryKey, true);
return this.OExistByPrimaryKeyHandle(param, oParser);
}
private bool OExistByPrimaryKeyHandle(object param, ObjectParser oParser)
{
object value = this.ExecuteScalar(string.Concat(new string[]
{
"select count(*) from ",
oParser.TableName,
" where ",
oParser.PrimaryPropertyInfo.Name,
"=@",
oParser.PrimaryPropertyInfo.Name
}), param, null, null, null);
return Convert.ToInt32(value) > 0;
}
public int ODeleteByPrimaryKey(object param, string tableName = null, string primaryKey = null, IDbTransaction transaction = null, int? commandTimeout = null)
{
ObjectParser oParser = ObjectParser.Bulid(this.GetArrayFirst(param) ?? param, tableName, primaryKey, true);
return this.ODeleteByPrimaryKeyHandle(param, transaction, commandTimeout, oParser);
}
public int ODeleteByPrimaryKey<T>(object param, string primaryKey = null, IDbTransaction transaction = null, int? commandTimeout = null)
{
ObjectParser oParser = ObjectParser.Bulid<T>(this.GetArrayFirst(param) ?? param, primaryKey, true);
return this.ODeleteByPrimaryKeyHandle(param, transaction, commandTimeout, oParser);
}
private int ODeleteByPrimaryKeyHandle(object param, IDbTransaction transaction, int? commandTimeout, ObjectParser oParser)
{
return this.Execute(string.Concat(new string[]
{
"delete from ",
oParser.TableName,
" where ",
oParser.PrimaryPropertyInfo.Name,
"=@",
oParser.PrimaryPropertyInfo.Name
}), param, transaction, commandTimeout, null);
}
public int ODelete(object param, string where, string tableName = null, IDbTransaction transaction = null, int? commandTimeout = null)
{
ObjectParser oParser = ObjectParser.Bulid(this.GetArrayFirst(param) ?? param, tableName, null, false);
return this.ODeleteHandle(param, where, transaction, commandTimeout, oParser);
}
public int ODelete<T>(object param, string where, IDbTransaction transaction = null, int? commandTimeout = null)
{
ObjectParser oParser = ObjectParser.Bulid<T>(this.GetArrayFirst(param) ?? param, null, false);
return this.ODeleteHandle(param, where, transaction, commandTimeout, oParser);
}
private int ODeleteHandle(object param, string where, IDbTransaction transaction, int? commandTimeout, ObjectParser oParser)
{
return this.Execute("delete from " + oParser.TableName + ((!string.IsNullOrEmpty(where)) ? (" where " + where) : ""), param, transaction, commandTimeout, null);
}
public int OCount(object param, string where = null, string tableName = null, IDbTransaction transaction = null)
{
ObjectParser objectParser = ObjectParser.Bulid(param, tableName, null, false);
return this.QuerySingle<int>("select count(*) from " + objectParser.TableName + ((!string.IsNullOrEmpty(where)) ? (" where " + where) : ""), param, transaction, null, null);
}
public int OCount<T>(object param, string where = null, IDbTransaction transaction = null, int? commandTimeout = null)
{
ObjectParser objectParser = ObjectParser.Bulid<T>(param, null, false);
return this.QuerySingle<int>("select count(*) from " + objectParser.TableName + ((!string.IsNullOrEmpty(where)) ? (" where " + where) : ""), param, transaction, null, null);
}
public int Execute(CommandDefinition command)
{
return this.Connection.Execute(command);
}
public int Execute(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.Execute(sql, param, transaction, commandTimeout, commandType);
}
public IDataReader ExecuteReader(CommandDefinition command)
{
return this.Connection.ExecuteReader(command);
}
public IDataReader ExecuteReader(CommandDefinition command, CommandBehavior commandBehavior)
{
return this.Connection.ExecuteReader(command, commandBehavior);
}
public IDataReader ExecuteReader(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.ExecuteReader(sql, param, transaction, commandTimeout, commandType);
}
public T ExecuteScalar<T>(CommandDefinition command)
{
return this.Connection.ExecuteScalar(command);
}
public object ExecuteScalar(CommandDefinition command)
{
return this.Connection.ExecuteScalar(command);
}
public T ExecuteScalar<T>(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.ExecuteScalar(sql, param, transaction, commandTimeout, commandType);
}
public object ExecuteScalar(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.ExecuteScalar(sql, param, transaction, commandTimeout, commandType);
}
public IEnumerable<T> Query<T>(CommandDefinition command)
{
return this.Connection.Query(command);
}
public IEnumerable<T> Query<T>(string sql, object param = null, IDbTransaction transaction = null, bool buffered = true, int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.Query(sql, param, transaction, buffered, commandTimeout, commandType);
}
[return: Dynamic(new bool[]
{
false,
true
})]
public IEnumerable<dynamic> Query(string sql, object param = null, IDbTransaction transaction = null, bool buffered = true, int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.Query(sql, param, transaction, buffered, commandTimeout, commandType);
}
public IEnumerable<object> Query(Type type, string sql, object param = null, IDbTransaction transaction = null, bool buffered = true, int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.Query(type, sql, param, transaction, buffered, commandTimeout, commandType);
}
public IEnumerable<TReturn> Query<TFirst, TSecond, TReturn>(string sql, Func<TFirst, TSecond, TReturn> map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.Query(sql, map, param, transaction, buffered, splitOn, commandTimeout, commandType);
}
public IEnumerable<TReturn> Query<TFirst, TSecond, TThird, TFourth, TFifth, TReturn>(string sql, Func<TFirst, TSecond, TThird, TFourth, TFifth, TReturn> map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.Query(sql, map, param, transaction, buffered, splitOn, commandTimeout, commandType);
}
public IEnumerable<TReturn> Query<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TReturn>(string sql, Func<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TReturn> map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.Query(sql, map, param, transaction, buffered, splitOn, commandTimeout, commandType);
}
public IEnumerable<TReturn> Query<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn>(string sql, Func<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn> map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.Query(sql, map, param, transaction, buffered, splitOn, commandTimeout, commandType);
}
public IEnumerable<TReturn> Query<TFirst, TSecond, TThird, TFourth, TReturn>(string sql, Func<TFirst, TSecond, TThird, TFourth, TReturn> map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.Query(sql, map, param, transaction, buffered, splitOn, commandTimeout, commandType);
}
public IEnumerable<TReturn> Query<TFirst, TSecond, TThird, TReturn>(string sql, Func<TFirst, TSecond, TThird, TReturn> map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.Query(sql, map, param, transaction, buffered, splitOn, commandTimeout, commandType);
}
public IEnumerable<TReturn> Query<TReturn>(string sql, Type[] types, Func<object[], TReturn> map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.Query(sql, types, map, param, transaction, buffered, splitOn, commandTimeout, commandType);
}
public T QueryFirst<T>(CommandDefinition command)
{
return this.Connection.QueryFirst(command);
}
[return: Dynamic]
public dynamic QueryFirst(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.QueryFirst(sql, param, transaction, commandTimeout, commandType);
}
public T QueryFirst<T>(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.QueryFirst(sql, param, transaction, commandTimeout, commandType);
}
public object QueryFirst(Type type, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.QueryFirst(type, sql, param, transaction, commandTimeout, commandType);
}
public T QueryFirstOrDefault<T>(CommandDefinition command)
{
return this.Connection.QueryFirstOrDefault(command);
}
[return: Dynamic]
public dynamic QueryFirstOrDefault(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.QueryFirstOrDefault(sql, param, transaction, commandTimeout, commandType);
}
public T QueryFirstOrDefault<T>(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.QueryFirstOrDefault(sql, param, transaction, commandTimeout, commandType);
}
public object QueryFirstOrDefault(Type type, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.QueryFirstOrDefault(type, sql, param, transaction, commandTimeout, commandType);
}
public SqlMapper.GridReader QueryMultiple(CommandDefinition command)
{
return this.Connection.QueryMultiple(command);
}
public SqlMapper.GridReader QueryMultiple(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.QueryMultiple(sql, param, transaction, commandTimeout, commandType);
}
public T QuerySingle<T>(CommandDefinition command)
{
return this.Connection.QuerySingle(command);
}
[return: Dynamic]
public dynamic QuerySingle(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.QuerySingle(sql, param, transaction, commandTimeout, commandType);
}
public T QuerySingle<T>(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.QuerySingle(sql, param, transaction, commandTimeout, commandType);
}
public object QuerySingle(Type type, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.QuerySingle(type, sql, param, transaction, commandTimeout, commandType);
}
public T QuerySingleOrDefault<T>(CommandDefinition command)
{
return this.Connection.QuerySingleOrDefault(command);
}
[return: Dynamic]
public dynamic QuerySingleOrDefault(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.QuerySingleOrDefault(sql, param, transaction, commandTimeout, commandType);
}
public T QuerySingleOrDefault<T>(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.QuerySingleOrDefault(sql, param, transaction, commandTimeout, commandType);
}
public object QuerySingleOrDefault(Type type, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
return this.Connection.QuerySingleOrDefault(type, sql, param, transaction, commandTimeout, commandType);
}
}
Nuget调用简单封装.的更多相关文章
- wcf第4步之原生调用简单封装
public interface IDemoServiceChannel : IDemoService, System.ServiceModel.IClientChannel { } public p ...
- .net core 中简单封装Dapper.Extensions 并使用sqlsuger自动生成实体类
引言 由公司需要使用dapper 同时支持多数据库 又需要支持实体类 又需要支持sql 还需要支持事务 所以采用了 dapper + dapperExtensions 并配套 生成实体类小工具的方 ...
- Android AsyncTask 深度理解、简单封装、任务队列分析、自定义线程池
前言:由于最近在做SDK的功能,需要设计线程池.看了很多资料不知道从何开始着手,突然发现了AsyncTask有对线程池的封装,so,就拿它开刀,本文将从AsyncTask的基本用法,到简单的封装,再到 ...
- FMDB简单封装和使用
工具:火狐浏览器+SQLite Manager插件 ; Xcode; FMDB库; 效果: 项目地址: https://github.com/sven713/PackFMDB 主要参考这两篇博客: 1 ...
- Android--Retrofit+RxJava的简单封装(三)
1,继续接着上一篇的讲讲,话说如果像上一篇这样的话,那么我们每一次请求一个结构都要创建一堆的Retrofit对象,而且代码都是相同的,我们可以试试封装一下 先创建一个HttpMethods类,将Ret ...
- 对pymysql的简单封装
#coding=utf-8 #!/usr/bin/python import pymysql class MYSQL: """ 对pymysql的简单封装 "& ...
- iOS开发——UI篇OC篇&UITableView简单封装
UITableView简单封装 UITableView时iOS开发中使用最多也是最重的一个UI空间,其实在App Store里面的%80以上的应用都用到了这个控件,所以就给大家介绍一下,前面的文章中也 ...
- MySQL的C++简单封装
/* *介绍:MySQL的简单封装,支持流操作输入输出MySQL语句,然而并没有什么软用,大二学生自娱自乐,有不足求指点 *作者:MrEO *日期:2016.3.26 */ 头文件 my_sql.h ...
- jquery简单封装
对Raphael画图标的一个jquery简单封装 公司要做一个项目的demo,要求地图上可以插红旗,所以就用到了Raphael. 因为是个demo,所以地图就用了一张图片,效果如下: 所以为了更好的封 ...
随机推荐
- Python学习第五堂课
Python学习第五堂课推荐电影:华尔街之狼 被拯救的姜哥 阿甘正传 辛德勒的名单 肖申克的救赎 上帝之城 焦土之城 绝美之城 #上节内容: 变量 if else 注释 # ""& ...
- mac安装brew简单方法
安装方法:命令行输入 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/ma ...
- 【转载】 “强化学习之父”萨顿:预测学习马上要火,AI将帮我们理解人类意识
原文地址: https://yq.aliyun.com/articles/400366 本文来自AI新媒体量子位(QbitAI) ------------------------------- ...
- Python学习之路基础篇--09Python基础,初识函数
函数可以分为内置函数 和 自定义函数.这次关注的主要是自定义函数.定义函数之后,就可以在任何需要它的地方调用. 1 返回值的重要性 返回值的3种情况 没有返回值 ---- 返回None 不定 retu ...
- Jmeter并发测试
链接推荐:https://blog.csdn.net/weixin_41291554/article/details/80492276
- 653. Two Sum IV - Input is a BST-easy
我不懂有没有收藏之类的功能,收藏别人的解法. tql,不懂为什么直接比较set里的值,不是两个数sum么 有一些答案都用到了iterator迭代器 http://www.cplusplus.com/r ...
- VS 2017 + opencv4.0
完全参考这一文章, 非常详细: https://blog.csdn.net/qq_41175905/article/details/80560429 记录自己遇到的问题: 1. VS 2017 专业版 ...
- 基于Linux-3.9.4的mykernel实验环境的极简内核分析
382 + 原创作品转载请注明出处 + https://github.com/mengning/linuxkernel/ 一.实验环境 win10 -> VMware -> Ubuntu1 ...
- Hot Chocolate 一个.net 平台的graphql 框架
在看昨天发布的新版技术雷达中,看到了一个.net 的graphql 框架Hot Chocolate 还是比较激动,尽管好久不搞 .net 了,但是这个框架还是值得看看的,后边学习下 参考资料 http ...
- click python cli 开发包
python click 包是一个方便的cli 开发包,我们可以用来开发强大的cli 应用 使用venv 进行环境准备,示例代码来自官方 venv 环境准备 python3 -m venv demoa ...