SqlsugarHelper.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. 
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Configuration;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Microsoft.Extensions.Configuration;
  9. using Microsoft.Extensions.DependencyInjection;
  10. using SqlSugar;
  11. namespace IoTIntegrationPlatform.Common
  12. {
  13. /// <summary>
  14. /// 静态SqlSugar扩展类
  15. /// </summary>
  16. public static class SqlsugarHelper
  17. {
  18. /// <summary>
  19. /// sqlsugarORM框架
  20. /// </summary>
  21. /// <param name="service">服务</param>
  22. /// <param name="configuration">配置文件</param>
  23. public static void SqlsugarDB(this IServiceCollection service, IConfiguration configuration)
  24. {
  25. SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig()
  26. {
  27. DbType = DbType.MySql,
  28. ConnectionString = configuration.GetConnectionString("SqlConnection"),
  29. InitKeyType = InitKeyType.Attribute,
  30. IsAutoCloseConnection = true,
  31. MoreSettings = new ConnMoreSettings
  32. {
  33. PgSqlIsAutoToLower = false
  34. },
  35. AopEvents = new AopEvents
  36. {
  37. OnLogExecuting = (sql, p) =>
  38. {
  39. //Log4NetHelper.WriteLog(null, Log4NetLevel.Info, sql);
  40. //Logging.Info("执行的sql:"+sql);
  41. }
  42. }
  43. });
  44. service.AddSingleton<ISqlSugarClient>(sqlSugar);
  45. }
  46. }
  47. }