智慧大脑
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

54 строки
1.9 KiB

  1. using System.Collections.Generic;
  2. using System.Data;
  3. using System.Threading.Tasks;
  4. using Dapper;
  5. using DapperExtensions;
  6. namespace DataSendApi.Program.Oracle
  7. {
  8. public static class DbContext
  9. {
  10. // 获取开启数据库的连接
  11. private static IDbConnection Db
  12. {
  13. get
  14. {
  15. //创建单一实例
  16. DapperHelper.GetInstance();
  17. return DapperHelper.OpenCurrentDbConnection();
  18. }
  19. }
  20. /// <summary>
  21. /// 查出一条记录的实体
  22. /// </summary>
  23. public static T QueryFirstOrDefault<T>(string sql, object param = null)
  24. {
  25. return Db.QueryFirstOrDefault<T>(sql, param);
  26. }
  27. /// <summary>
  28. /// 查出多条记录的实体泛型集合
  29. /// </summary>
  30. public static IEnumerable<T> Query<T>(string sql, object param = null, IDbTransaction transaction = null, bool buffered = true, int? commandTimeout = null, CommandType? commandType = null)
  31. {
  32. return Db.Query<T>(sql, param, transaction, buffered, commandTimeout, commandType);
  33. }
  34. /// <summary>
  35. /// 执行sql 返回受影响行数
  36. /// </summary>
  37. public static int Execute(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
  38. {
  39. return Db.Execute(sql, param, transaction, commandTimeout, commandType);
  40. }
  41. /// <summary>
  42. /// 执行sql 返回首行首列
  43. /// </summary>
  44. public static T ExecuteScalar<T>(string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
  45. {
  46. return Db.ExecuteScalar<T>(sql, param, transaction, commandTimeout, commandType);
  47. }
  48. }
  49. }