DbContext.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using SqlSugar;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using TEAMModelOS.SDK.Context.Configuration;
  6. namespace TEAMModelOS.SDK.Module.SqlSugar.Configuration
  7. {
  8. public class DbContext
  9. {
  10. public DbContext()
  11. {
  12. Db = new SqlSugarClient(new ConnectionConfig()
  13. {
  14. ConnectionString = BaseConfigModel.Configuration["DbConnection:MySqlConnectionString"],
  15. DbType = DbType.MySql,
  16. IsAutoCloseConnection = true
  17. });
  18. //调式代码 用来打印SQL
  19. Db.Aop.OnLogExecuting = (sql, pars) =>
  20. {
  21. string s = sql;
  22. //Console.WriteLine(sql + "\r\n" +
  23. // Db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
  24. //Console.WriteLine();
  25. };
  26. }
  27. public SqlSugarClient Db;//用来处理事务多表查询和复杂的操作
  28. public DbSet<DbModel> GetDb<DbModel>() where DbModel : class, new()
  29. {
  30. return new DbSet<DbModel>(Db);
  31. }
  32. }
  33. }