集成,总结MES功能
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

53 rindas
2.0 KiB

  1. using Furion;
  2. using Microsoft.Extensions.Configuration;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using SqlSugar;
  5. using System;
  6. using System.Collections.Generic;
  7. namespace BPA.MES.Base.Core
  8. {
  9. /// <summary>
  10. /// 名 称 :数据库启动类
  11. /// 创 建 人 :yangxiao
  12. /// 创建时间 : 2023/3/23 14:09:30
  13. /// 描 述 :
  14. /// </summary>
  15. public static class SqlsugarSetup
  16. {
  17. public static void AddSqlsugarSetup(this IServiceCollection services, IConfiguration configuration, string dbName = "ConnectionString")
  18. {
  19. //如果多个数数据库传 List<ConnectionConfig>
  20. var dbs = App.GetConfig<List<ConnectionConfig>>("ConnectionConfigs")[0];
  21. var configConnection = new ConnectionConfig()
  22. {
  23. DbType = dbs.DbType,
  24. ConnectionString = dbs.ConnectionString,
  25. IsAutoCloseConnection = dbs.IsAutoCloseConnection,
  26. };
  27. SqlSugarScope sqlSugar = new SqlSugarScope(configConnection,
  28. db =>
  29. {
  30. //单例参数配置,所有上下文生效
  31. db.Aop.OnLogExecuting = (sql, pars) =>
  32. {
  33. Console.WriteLine(sql);//输出sql
  34. };
  35. db.Aop.DataExecuting = (oldValue, entityInfo) =>
  36. {
  37. if (entityInfo.PropertyName == "CreateTime" && entityInfo.OperationType == DataFilterType.InsertByObject)
  38. {
  39. entityInfo.SetValue(DateTime.Now);
  40. };
  41. if (entityInfo.PropertyName == "CreateDate" && entityInfo.OperationType == DataFilterType.InsertByObject)
  42. {
  43. entityInfo.SetValue(DateTime.Now);
  44. };
  45. };
  46. }
  47. );
  48. services.AddSingleton<ISqlSugarClient>(sqlSugar);//这边是SqlSugarScope用AddSingleton
  49. }
  50. }
  51. }