From 1b261b3177539c3c630d5a3d07fdb93d036f65b3 Mon Sep 17 00:00:00 2001 From: "guoshun.du" Date: Tue, 31 Dec 2024 14:52:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0CheckConnectionExecuting?= =?UTF-8?q?=E5=92=8CCheckConnectionExecuted=E4=BA=8B=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E7=9B=91=E5=90=AC=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E4=BA=8B=E4=BB=B6=EF=BC=8C=E6=96=B9=E4=BE=BF?= =?UTF-8?q?=E6=8E=92=E6=9F=A5=E6=98=AF=E5=90=A6=E6=98=AF=E5=9B=A0=E4=B8=BA?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E6=B1=A0=E7=B4=A7=E7=BC=BA=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84=E8=BF=9E=E6=8E=A5=E9=80=9F=E5=BA=A6=E6=85=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tools/UtilMethods.cs | 2 ++ .../Abstract/AdoProvider/AdoProvider.cs | 33 +++++++++++++++++++ .../Abstract/AopProvider/AopProvider.cs | 3 ++ .../SqlSugar/Entities/ConnectionConfig.cs | 2 ++ Src/Asp.NetCore2/SqlSugar/Interface/IAdo.cs | 27 ++++++++------- .../Realization/QuestDB/QuestDBProvider.cs | 2 ++ .../SqlSugar/Utilities/UtilMethods.cs | 2 ++ 7 files changed, 59 insertions(+), 12 deletions(-) diff --git a/Src/Asp.NetCore2/SqlSugar.TDSQLForPGODBC/Tools/UtilMethods.cs b/Src/Asp.NetCore2/SqlSugar.TDSQLForPGODBC/Tools/UtilMethods.cs index 0cd31b003..5f7053b29 100644 --- a/Src/Asp.NetCore2/SqlSugar.TDSQLForPGODBC/Tools/UtilMethods.cs +++ b/Src/Asp.NetCore2/SqlSugar.TDSQLForPGODBC/Tools/UtilMethods.cs @@ -599,6 +599,8 @@ namespace SqlSugar.TDSQLForPGODBC OnLogExecuted = it.AopEvents?.OnLogExecuted, OnLogExecuting = it.AopEvents?.OnLogExecuting, DataExecuted = it.AopEvents?.DataExecuted, + CheckConnectionExecuted = it.AopEvents?.CheckConnectionExecuted, + CheckConnectionExecuting = it.AopEvents?.CheckConnectionExecuting, }, ConfigId = it.ConfigId, ConfigureExternalServices = it.ConfigureExternalServices == null ? null : new ConfigureExternalServices() diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs index b452294e4..028ddf298 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs @@ -39,6 +39,7 @@ namespace SqlSugar internal bool OldClearParameters { get; set; } public IDataParameterCollection DataReaderParameters { get; set; } public TimeSpan SqlExecutionTime { get { return AfterTime - BeforeTime; } } + public TimeSpan ConnectionExecutionTime { get { return CheckConnectionAfterTime - CheckConnectionBeforeTime; } } /// /// Add, delete and modify: the number of affected items; /// @@ -47,6 +48,8 @@ namespace SqlSugar public bool IsDisableMasterSlaveSeparation { get; set; } internal DateTime BeforeTime = DateTime.MinValue; internal DateTime AfterTime = DateTime.MinValue; + internal DateTime CheckConnectionBeforeTime = DateTime.MinValue; + internal DateTime CheckConnectionAfterTime = DateTime.MinValue; public virtual IDbBind DbBind { get @@ -66,6 +69,8 @@ namespace SqlSugar public virtual bool IsClearParameters { get; set; } public virtual Action LogEventStarting => this.Context.CurrentConnectionConfig.AopEvents?.OnLogExecuting; public virtual Action LogEventCompleted => this.Context.CurrentConnectionConfig.AopEvents?.OnLogExecuted; + public virtual Action CheckConnectionExecuting => this.Context.CurrentConnectionConfig.AopEvents?.CheckConnectionExecuting; + public virtual Action CheckConnectionExecuted => this.Context.CurrentConnectionConfig.AopEvents?.CheckConnectionExecuted; public virtual Func> ProcessingEventStartingSQL => this.Context.CurrentConnectionConfig.AopEvents?.OnExecutingChangeSql; protected virtual Func FormatSql { get; set; } public virtual Action ErrorEvent => this.Context.CurrentConnectionConfig.AopEvents?.OnError; @@ -175,6 +180,7 @@ namespace SqlSugar } public virtual void CheckConnection() { + this.CheckConnectionBefore(this.Connection); if (this.Connection.State != ConnectionState.Open) { try @@ -190,10 +196,12 @@ namespace SqlSugar Check.Exception(true, ErrorMessage.ConnnectionOpen, ex.Message+$"DbType=\"{this.Context.CurrentConnectionConfig.DbType}\";ConfigId=\"{this.Context.CurrentConnectionConfig.ConfigId}\""); } } + this.CheckConnectionAfter(this.Connection); } public virtual async Task CheckConnectionAsync() { + this.CheckConnectionBefore(this.Connection); if (this.Connection.State != ConnectionState.Open) { try @@ -205,6 +213,31 @@ namespace SqlSugar Check.Exception(true, ErrorMessage.ConnnectionOpen, ex.Message + $"DbType=\"{this.Context.CurrentConnectionConfig.DbType}\";ConfigId=\"{this.Context.CurrentConnectionConfig.ConfigId}\""); } } + this.CheckConnectionAfter(this.Connection); + } + public virtual void CheckConnectionBefore(IDbConnection Connection) + { + this.CheckConnectionBeforeTime = DateTime.Now; + if (this.IsEnableLogEvent) + { + Action action = CheckConnectionExecuting; + if (action != null) + { + action(Connection); + } + } + } + public virtual void CheckConnectionAfter(IDbConnection Connection) + { + this.CheckConnectionAfterTime = DateTime.Now; + if (this.IsEnableLogEvent) + { + Action action = CheckConnectionExecuted; + if (action != null) + { + action(Connection,this.ConnectionExecutionTime); + } + } } #endregion diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/AopProvider/AopProvider.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/AopProvider/AopProvider.cs index 01949351d..0055b586f 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/AopProvider/AopProvider.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/AopProvider/AopProvider.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Data; using System.Linq; using System.Text; @@ -22,5 +23,7 @@ namespace SqlSugar public virtual Action DataExecuting { set { this.Context.CurrentConnectionConfig.AopEvents.DataExecuting = value; } } public Action DataChangesExecuted { set { this.Context.CurrentConnectionConfig.AopEvents.DataChangesExecuted = value; } } public virtual Action DataExecuted { set { this.Context.CurrentConnectionConfig.AopEvents.DataExecuted = value; } } + public Action CheckConnectionExecuting { set { this.Context.CurrentConnectionConfig.AopEvents.CheckConnectionExecuting = value; } } + public Action CheckConnectionExecuted { set { this.Context.CurrentConnectionConfig.AopEvents.CheckConnectionExecuted = value; } } } } diff --git a/Src/Asp.NetCore2/SqlSugar/Entities/ConnectionConfig.cs b/Src/Asp.NetCore2/SqlSugar/Entities/ConnectionConfig.cs index d30b4dce4..a7082f67d 100644 --- a/Src/Asp.NetCore2/SqlSugar/Entities/ConnectionConfig.cs +++ b/Src/Asp.NetCore2/SqlSugar/Entities/ConnectionConfig.cs @@ -94,6 +94,8 @@ namespace SqlSugar public Action DataExecuting { get; set; } public Action DataChangesExecuted { get; set; } public Action DataExecuted { get; set; } + public Action CheckConnectionExecuting { get; set; } + public Action CheckConnectionExecuted { get; set; } } public class ConfigureExternalServices { diff --git a/Src/Asp.NetCore2/SqlSugar/Interface/IAdo.cs b/Src/Asp.NetCore2/SqlSugar/Interface/IAdo.cs index 2331712cd..13e872cc3 100644 --- a/Src/Asp.NetCore2/SqlSugar/Interface/IAdo.cs +++ b/Src/Asp.NetCore2/SqlSugar/Interface/IAdo.cs @@ -18,11 +18,13 @@ namespace SqlSugar IDataParameter[] ToIDbDataParameter(params SugarParameter[] pars); SugarParameter[] GetParameters(object obj, PropertyInfo[] propertyInfo = null); SqlSugarProvider Context { get; set; } + void CheckConnectionAfter(IDbConnection Connection); + void CheckConnectionBefore(IDbConnection Connection); void ExecuteBefore(string sql, SugarParameter[] pars); void ExecuteAfter(string sql, SugarParameter[] pars); bool IsAnyTran(); bool IsNoTran(); - bool IsEnableLogEvent{get;set;} + bool IsEnableLogEvent { get; set; } StackTraceInfo SqlStackTrace { get; } IDataParameterCollection DataReaderParameters { get; set; } CommandType CommandType { get; set; } @@ -31,6 +33,7 @@ namespace SqlSugar bool IsClearParameters { get; set; } int CommandTimeOut { get; set; } TimeSpan SqlExecutionTime { get; } + TimeSpan ConnectionExecutionTime { get; } int SqlExecuteCount { get; } IDbBind DbBind { get; } void SetCommandToAdapter(IDataAdapter adapter, DbCommand command); @@ -79,7 +82,7 @@ namespace SqlSugar Task ExecuteCommandAsync(string sql, params SugarParameter[] parameters); Task ExecuteCommandAsync(string sql, object parameters); - Task ExecuteCommandAsync(string sql, object parameters,CancellationToken cancellationToken); + Task ExecuteCommandAsync(string sql, object parameters, CancellationToken cancellationToken); Task ExecuteCommandAsync(string sql, List parameters); string GetString(string sql, object parameters); @@ -99,9 +102,9 @@ namespace SqlSugar Task GetIntAsync(string sql, List parameters); - long GetLong(string sql, object pars=null); + long GetLong(string sql, object pars = null); - Task GetLongAsync(string sql, object pars=null); + Task GetLongAsync(string sql, object pars = null); Double GetDouble(string sql, object parameters); @@ -132,12 +135,12 @@ namespace SqlSugar Task GetDateTimeAsync(string sql, List parameters); - Tuple, List> SqlQuery(string sql, object parameters = null); - Tuple, List, List> SqlQuery(string sql, object parameters = null); - Tuple, List, List,List> SqlQuery(string sql, object parameters = null); - Tuple, List, List, List, List> SqlQuery(string sql, object parameters = null); - Tuple, List, List, List, List, List> SqlQuery(string sql, object parameters = null); - Tuple, List, List, List, List, List, List> SqlQuery(string sql, object parameters = null); + Tuple, List> SqlQuery(string sql, object parameters = null); + Tuple, List, List> SqlQuery(string sql, object parameters = null); + Tuple, List, List, List> SqlQuery(string sql, object parameters = null); + Tuple, List, List, List, List> SqlQuery(string sql, object parameters = null); + Tuple, List, List, List, List, List> SqlQuery(string sql, object parameters = null); + Tuple, List, List, List, List, List, List> SqlQuery(string sql, object parameters = null); Task, List>> SqlQueryAsync(string sql, object parameters = null); Task, List, List>> SqlQueryAsync(string sql, object parameters = null); @@ -153,7 +156,7 @@ namespace SqlSugar List MasterSqlQuery(string sql, object parameters = null); Task> SqlQueryAsync(string sql, object parameters = null); - Task> SqlQueryAsync(string sql, object parameters,CancellationToken token); + Task> SqlQueryAsync(string sql, object parameters, CancellationToken token); Task> SqlQueryAsync(string sql, List parameters); Task> SqlQueryAsync(string sql, params SugarParameter[] parameters); @@ -191,6 +194,6 @@ namespace SqlSugar Task> UseTranAsync(Func action, Action errorCallBack = null); Task> UseTranAsync(Func> action, Action errorCallBack = null); IAdo UseStoredProcedure(); - + } } diff --git a/Src/Asp.NetCore2/SqlSugar/Realization/QuestDB/QuestDBProvider.cs b/Src/Asp.NetCore2/SqlSugar/Realization/QuestDB/QuestDBProvider.cs index 35009d194..f23e3850c 100644 --- a/Src/Asp.NetCore2/SqlSugar/Realization/QuestDB/QuestDBProvider.cs +++ b/Src/Asp.NetCore2/SqlSugar/Realization/QuestDB/QuestDBProvider.cs @@ -80,6 +80,7 @@ namespace SqlSugar /// public override void CheckConnection() { + this.CheckConnectionBefore(this.Connection); if (this.Connection.State != ConnectionState.Open) { try @@ -104,6 +105,7 @@ namespace SqlSugar Check.Exception(true, ErrorMessage.ConnnectionOpen, ex.Message); } } + this.CheckConnectionAfter(this.Connection); } public override void SetCommandToAdapter(IDataAdapter dataAdapter, DbCommand command) { diff --git a/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs b/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs index 7005b7537..0c70d49a3 100644 --- a/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs +++ b/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs @@ -662,6 +662,8 @@ namespace SqlSugar OnLogExecuted=it.AopEvents?.OnLogExecuted, OnLogExecuting= it.AopEvents?.OnLogExecuting, DataExecuted = it.AopEvents?.DataExecuted, + CheckConnectionExecuted = it.AopEvents?.CheckConnectionExecuted, + CheckConnectionExecuting = it.AopEvents?.CheckConnectionExecuting, }, ConfigId = it.ConfigId, ConfigureExternalServices =it.ConfigureExternalServices==null?null:new ConfigureExternalServices() { -- Gitee From bc8aa0a459f002a413ba100a76c2ca280401ddca Mon Sep 17 00:00:00 2001 From: "guoshun.du" Date: Tue, 31 Dec 2024 15:03:12 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OnGetDataReadering?= =?UTF-8?q?=E5=92=8COnGetDataReadered=E4=BA=8B=E4=BB=B6=EF=BC=8C=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E7=9B=91=E5=90=ACSQL=E6=89=A7=E8=A1=8C=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E6=95=B0=E6=8D=AE=E8=AF=BB=E5=8F=96=E5=BE=97=E8=80=97?= =?UTF-8?q?=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tools/UtilMethods.cs | 2 + .../Abstract/AdoProvider/AdoProvider.cs | 55 ++++++++++++++++++- .../Abstract/AopProvider/AopProvider.cs | 2 + .../QueryableProvider/QueryableHelper.cs | 12 +++- .../SqlSugar/Entities/ConnectionConfig.cs | 2 + Src/Asp.NetCore2/SqlSugar/Interface/IAdo.cs | 2 + .../SqlSugar/Utilities/UtilMethods.cs | 2 + 7 files changed, 73 insertions(+), 4 deletions(-) diff --git a/Src/Asp.NetCore2/SqlSugar.TDSQLForPGODBC/Tools/UtilMethods.cs b/Src/Asp.NetCore2/SqlSugar.TDSQLForPGODBC/Tools/UtilMethods.cs index 5f7053b29..c8e6a3e05 100644 --- a/Src/Asp.NetCore2/SqlSugar.TDSQLForPGODBC/Tools/UtilMethods.cs +++ b/Src/Asp.NetCore2/SqlSugar.TDSQLForPGODBC/Tools/UtilMethods.cs @@ -601,6 +601,8 @@ namespace SqlSugar.TDSQLForPGODBC DataExecuted = it.AopEvents?.DataExecuted, CheckConnectionExecuted = it.AopEvents?.CheckConnectionExecuted, CheckConnectionExecuting = it.AopEvents?.CheckConnectionExecuting, + OnGetDataReadered = it.AopEvents?.OnGetDataReadered, + OnGetDataReadering = it.AopEvents?.OnGetDataReadering, }, ConfigId = it.ConfigId, ConfigureExternalServices = it.ConfigureExternalServices == null ? null : new ConfigureExternalServices() diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs index 028ddf298..94058536b 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/AdoProvider/AdoProvider.cs @@ -40,6 +40,7 @@ namespace SqlSugar public IDataParameterCollection DataReaderParameters { get; set; } public TimeSpan SqlExecutionTime { get { return AfterTime - BeforeTime; } } public TimeSpan ConnectionExecutionTime { get { return CheckConnectionAfterTime - CheckConnectionBeforeTime; } } + public TimeSpan GetDataExecutionTime { get { return GetDataAfterTime - GetDataBeforeTime; } } /// /// Add, delete and modify: the number of affected items; /// @@ -48,6 +49,8 @@ namespace SqlSugar public bool IsDisableMasterSlaveSeparation { get; set; } internal DateTime BeforeTime = DateTime.MinValue; internal DateTime AfterTime = DateTime.MinValue; + internal DateTime GetDataBeforeTime = DateTime.MinValue; + internal DateTime GetDataAfterTime = DateTime.MinValue; internal DateTime CheckConnectionBeforeTime = DateTime.MinValue; internal DateTime CheckConnectionAfterTime = DateTime.MinValue; public virtual IDbBind DbBind @@ -71,6 +74,8 @@ namespace SqlSugar public virtual Action LogEventCompleted => this.Context.CurrentConnectionConfig.AopEvents?.OnLogExecuted; public virtual Action CheckConnectionExecuting => this.Context.CurrentConnectionConfig.AopEvents?.CheckConnectionExecuting; public virtual Action CheckConnectionExecuted => this.Context.CurrentConnectionConfig.AopEvents?.CheckConnectionExecuted; + public virtual Action OnGetDataReadering => this.Context.CurrentConnectionConfig.AopEvents?.OnGetDataReadering; + public virtual Action OnGetDataReadered => this.Context.CurrentConnectionConfig.AopEvents?.OnGetDataReadered; public virtual Func> ProcessingEventStartingSQL => this.Context.CurrentConnectionConfig.AopEvents?.OnExecutingChangeSql; protected virtual Func FormatSql { get; set; } public virtual Action ErrorEvent => this.Context.CurrentConnectionConfig.AopEvents?.OnError; @@ -1048,7 +1053,10 @@ namespace SqlSugar builder.SqlQueryBuilder.sql.Append(sql); if (parsmeterArray != null && parsmeterArray.Any()) builder.SqlQueryBuilder.Parameters.AddRange(parsmeterArray); - using (var dataReader = this.GetDataReader(builder.SqlQueryBuilder.ToSqlString(), builder.SqlQueryBuilder.Parameters.ToArray())) + string sqlString = builder.SqlQueryBuilder.ToString(); + SugarParameter[] Parameters = builder.SqlQueryBuilder.Parameters.ToArray(); + this.GetDataBefore(sqlString, Parameters); + using (var dataReader = this.GetDataReader(sqlString, Parameters)) { DbDataReader DbReader = (DbDataReader)dataReader; List result = new List(); @@ -1109,6 +1117,7 @@ namespace SqlSugar } this.Context.Ado.DataReaderParameters = null; } + this.GetDataAfter(sqlString, Parameters); return Tuple.Create, List, List, List, List, List, List>(result, result2, result3, result4, result5, result6, result7); } } @@ -1173,7 +1182,10 @@ namespace SqlSugar builder.SqlQueryBuilder.sql.Append(sql); if (parsmeterArray != null && parsmeterArray.Any()) builder.SqlQueryBuilder.Parameters.AddRange(parsmeterArray); - using (var dataReader = await this.GetDataReaderAsync(builder.SqlQueryBuilder.ToSqlString(), builder.SqlQueryBuilder.Parameters.ToArray())) + string sqlString = builder.SqlQueryBuilder.ToSqlString(); + SugarParameter[] Parameters = builder.SqlQueryBuilder.Parameters.ToArray(); + this.GetDataBefore(sqlString, Parameters); + using (var dataReader = await this.GetDataReaderAsync(sqlString, Parameters)) { DbDataReader DbReader = (DbDataReader)dataReader; List result = new List(); @@ -1230,6 +1242,7 @@ namespace SqlSugar } this.Context.Ado.DataReaderParameters = null; } + this.GetDataAfter(sqlString, Parameters); return Tuple.Create, List, List, List, List, List, List>(result, result2, result3, result4, result5, result6, result7); } } @@ -1584,6 +1597,44 @@ namespace SqlSugar this.OldClearParameters = false; } } + public virtual void GetDataBefore(string sql, SugarParameter[] parameters) + { + this.GetDataBeforeTime = DateTime.Now; + if (this.IsEnableLogEvent) + { + Action action = OnGetDataReadering; + if (action != null) + { + if (parameters == null || parameters.Length == 0) + { + action(sql, new SugarParameter[] { }); + } + else + { + action(sql, parameters); + } + } + } + } + public virtual void GetDataAfter(string sql, SugarParameter[] parameters) + { + this.GetDataAfterTime = DateTime.Now; + if (this.IsEnableLogEvent) + { + Action action = OnGetDataReadered; + if (action != null) + { + if (parameters == null || parameters.Length == 0) + { + action(sql, new SugarParameter[] { }, GetDataExecutionTime); + } + else + { + action(sql, parameters, GetDataExecutionTime); + } + } + } + } public virtual SugarParameter[] GetParameters(object parameters, PropertyInfo[] propertyInfo = null) { if (parameters == null) return null; diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/AopProvider/AopProvider.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/AopProvider/AopProvider.cs index 0055b586f..aee0d3e54 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/AopProvider/AopProvider.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/AopProvider/AopProvider.cs @@ -25,5 +25,7 @@ namespace SqlSugar public virtual Action DataExecuted { set { this.Context.CurrentConnectionConfig.AopEvents.DataExecuted = value; } } public Action CheckConnectionExecuting { set { this.Context.CurrentConnectionConfig.AopEvents.CheckConnectionExecuting = value; } } public Action CheckConnectionExecuted { set { this.Context.CurrentConnectionConfig.AopEvents.CheckConnectionExecuted = value; } } + public Action OnGetDataReadering { set { this.Context.CurrentConnectionConfig.AopEvents.OnGetDataReadering = value; } } + public Action OnGetDataReadered { set { this.Context.CurrentConnectionConfig.AopEvents.OnGetDataReadered = value; } } } } diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs index 89fac2556..05dcdab7e 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs @@ -1885,8 +1885,12 @@ namespace SqlSugar var entityType = typeof(TResult); bool isChangeQueryableSlave = GetIsSlaveQuery(); bool isChangeQueryableMasterSlave = GetIsMasterQuery(); - var dataReader = this.Db.GetDataReader(sqlObj.Key, sqlObj.Value.ToArray()); + string sqlString = sqlObj.Key; + SugarParameter[] parameters = sqlObj.Value.ToArray(); + var dataReader = this.Db.GetDataReader(sqlString, parameters); + this.Db.GetDataBefore(sqlString, parameters); result = GetData(isComplexModel, entityType, dataReader); + this.Db.GetDataAfter(sqlString, parameters); RestChangeMasterQuery(isChangeQueryableMasterSlave); RestChangeSlaveQuery(isChangeQueryableSlave); return result; @@ -1898,8 +1902,12 @@ namespace SqlSugar var entityType = typeof(TResult); bool isChangeQueryableSlave = GetIsSlaveQuery(); bool isChangeQueryableMasterSlave = GetIsMasterQuery(); - var dataReader = await this.Db.GetDataReaderAsync(sqlObj.Key, sqlObj.Value.ToArray()); + string sqlString = sqlObj.Key; + SugarParameter[] parameters = sqlObj.Value.ToArray(); + var dataReader = await this.Db.GetDataReaderAsync(sqlString, parameters); + this.Db.GetDataBefore(sqlString, parameters); result = await GetDataAsync(isComplexModel, entityType, dataReader); + this.Db.GetDataAfter(sqlString, parameters); RestChangeMasterQuery(isChangeQueryableMasterSlave); RestChangeSlaveQuery(isChangeQueryableSlave); return result; diff --git a/Src/Asp.NetCore2/SqlSugar/Entities/ConnectionConfig.cs b/Src/Asp.NetCore2/SqlSugar/Entities/ConnectionConfig.cs index a7082f67d..7c9babcc9 100644 --- a/Src/Asp.NetCore2/SqlSugar/Entities/ConnectionConfig.cs +++ b/Src/Asp.NetCore2/SqlSugar/Entities/ConnectionConfig.cs @@ -96,6 +96,8 @@ namespace SqlSugar public Action DataExecuted { get; set; } public Action CheckConnectionExecuting { get; set; } public Action CheckConnectionExecuted { get; set; } + public Action OnGetDataReadering { get; set; } + public Action OnGetDataReadered { get; set; } } public class ConfigureExternalServices { diff --git a/Src/Asp.NetCore2/SqlSugar/Interface/IAdo.cs b/Src/Asp.NetCore2/SqlSugar/Interface/IAdo.cs index 13e872cc3..549cc986a 100644 --- a/Src/Asp.NetCore2/SqlSugar/Interface/IAdo.cs +++ b/Src/Asp.NetCore2/SqlSugar/Interface/IAdo.cs @@ -22,6 +22,8 @@ namespace SqlSugar void CheckConnectionBefore(IDbConnection Connection); void ExecuteBefore(string sql, SugarParameter[] pars); void ExecuteAfter(string sql, SugarParameter[] pars); + void GetDataBefore(string sql, SugarParameter[] parameters); + void GetDataAfter(string sql, SugarParameter[] parameters); bool IsAnyTran(); bool IsNoTran(); bool IsEnableLogEvent { get; set; } diff --git a/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs b/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs index 0c70d49a3..134f11607 100644 --- a/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs +++ b/Src/Asp.NetCore2/SqlSugar/Utilities/UtilMethods.cs @@ -664,6 +664,8 @@ namespace SqlSugar DataExecuted = it.AopEvents?.DataExecuted, CheckConnectionExecuted = it.AopEvents?.CheckConnectionExecuted, CheckConnectionExecuting = it.AopEvents?.CheckConnectionExecuting, + OnGetDataReadered= it.AopEvents?.OnGetDataReadered, + OnGetDataReadering = it.AopEvents?.OnGetDataReadering, }, ConfigId = it.ConfigId, ConfigureExternalServices =it.ConfigureExternalServices==null?null:new ConfigureExternalServices() { -- Gitee