|
- 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();
- }
- }
-
- /// <summary>
- /// 查出一条记录的实体
- /// </summary>
- public static T QueryFirstOrDefault<T>(string sql, object param = null)
- {
-
- return Db.QueryFirstOrDefault<T>(sql, param);
- }
- /// <summary>
- /// 查出多条记录的实体泛型集合
- /// </summary>
- public static IEnumerable<T> Query<T>(string sql, object param = null, IDbTransaction transaction = null, bool buffered = true, int? commandTimeout = null, CommandType? commandType = null)
- {
- return Db.Query<T>(sql, param, transaction, buffered, commandTimeout, commandType);
- }
-
- /// <summary>
- /// 执行sql 返回受影响行数
- /// </summary>
- 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);
- }
-
- /// <summary>
- /// 执行sql 返回首行首列
- /// </summary>
- public static T ExecuteScalar<T>(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
- {
- return Db.ExecuteScalar<T>(sql, param, transaction, commandTimeout, commandType);
- }
- }
- }
|