| | |
| | | /// 数据库帮助类:包括单例模式和创建新连接的方法 |
| | | /// </summary> |
| | | public static class DbHelper { |
| | | private static readonly SqlSugarScope _sqlSugar; |
| | | private static SqlSugarScope _sqlSugar; |
| | | |
| | | static DbHelper() { |
| | | Init(); |
| | | } |
| | | |
| | | public static void Init() { |
| | | _sqlSugar = new SqlSugarScope(new ConnectionConfig() { |
| | | ConnectionString = Settings.Config.SqlServer, |
| | | DbType = DbType.SqlServer, |
| | |
| | | }, |
| | | db => { |
| | | // 监控所有超过1秒的Sql |
| | | db.Aop.OnLogExecuted = (sql, p) => |
| | | { |
| | | db.Aop.OnLogExecuted = (sql, p) => { |
| | | // 执行时间超过1秒 |
| | | if (db.Ado.SqlExecutionTime.TotalSeconds > 1) { |
| | | Console.WriteLine(sql + "\r\n" + db.Utilities.SerializeObject(p.ToDictionary(it => it.ParameterName, it => it.Value))); |