using System.Collections.Generic; using System.Data; using System.Threading.Tasks; using Dapper; using DapperExtensions; namespace DataSendApi.Program.Oracle { public static class DbContext { // 获取开启数据库的连接 private static IDbConnection Db { get { //创建单一实例 DapperHelper.GetInstance(); return DapperHelper.OpenCurrentDbConnection(); } } /// /// 查出一条记录的实体 /// public static T QueryFirstOrDefault(string sql, object param = null) { return Db.QueryFirstOrDefault(sql, param); } /// /// 查出多条记录的实体泛型集合 /// public static IEnumerable Query(string sql, object param = null, IDbTransaction transaction = null, bool buffered = true, int? commandTimeout = null, CommandType? commandType = null) { return Db.Query(sql, param, transaction, buffered, commandTimeout, commandType); } /// /// 执行sql 返回受影响行数 /// public static int Execute(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null) { return Db.Execute(sql, param, transaction, commandTimeout, commandType); } /// /// 执行sql 返回首行首列 /// public static T ExecuteScalar(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null) { return Db.ExecuteScalar(sql, param, transaction, commandTimeout, commandType); } } }