Skip to content

Commit 85ab2b1

Browse files
committed
- 增加 部分 LocalExecuteScalar Aop.CommandAfter 事件;#1481
1 parent 62f4e42 commit 85ab2b1

File tree

8 files changed

+113
-9
lines changed

8 files changed

+113
-9
lines changed

Providers/FreeSql.Provider.ClickHouse/ClickHouseCodeFirst.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,21 @@ object LocalExecuteScalar(string db, string sql)
482482
cmd.CommandText = sql;
483483
cmd.CommandType = CommandType.Text;
484484
var before = new Aop.CommandBeforeEventArgs(cmd);
485-
this._orm?.Aop.CommandBeforeHandler?.Invoke(this._orm, before);
486-
return cmd.ExecuteScalar();
485+
this._orm?.Aop.CommandBeforeHandler?.Invoke(this._orm, before);
486+
Exception afterException = null;
487+
try
488+
{
489+
return cmd.ExecuteScalar();
490+
}
491+
catch (Exception ex)
492+
{
493+
afterException = ex;
494+
throw;
495+
}
496+
finally
497+
{
498+
this._orm?.Aop.CommandAfterHandler?.Invoke(this._orm, new Aop.CommandAfterEventArgs(before, afterException, null));
499+
}
487500
}
488501
}
489502
finally

Providers/FreeSql.Provider.Custom/MySql/CustomMySqlCodeFirst.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,20 @@ object LocalExecuteScalar(string db, string sql)
384384
cmd.CommandType = CommandType.Text;
385385
var before = new Aop.CommandBeforeEventArgs(cmd);
386386
this._orm?.Aop.CommandBeforeHandler?.Invoke(this._orm, before);
387-
return cmd.ExecuteScalar();
387+
Exception afterException = null;
388+
try
389+
{
390+
return cmd.ExecuteScalar();
391+
}
392+
catch (Exception ex)
393+
{
394+
afterException = ex;
395+
throw;
396+
}
397+
finally
398+
{
399+
this._orm?.Aop.CommandAfterHandler?.Invoke(this._orm, new Aop.CommandAfterEventArgs(before, afterException, null));
400+
}
388401
}
389402
}
390403
finally

Providers/FreeSql.Provider.Custom/SqlServer/CustomSqlServerCodeFirst.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,20 @@ object LocalExecuteScalar(string db, string sql)
476476
cmd.CommandType = CommandType.Text;
477477
var before = new Aop.CommandBeforeEventArgs(cmd);
478478
this._orm?.Aop.CommandBeforeHandler?.Invoke(this._orm, before);
479-
return cmd.ExecuteScalar();
479+
Exception afterException = null;
480+
try
481+
{
482+
return cmd.ExecuteScalar();
483+
}
484+
catch (Exception ex)
485+
{
486+
afterException = ex;
487+
throw;
488+
}
489+
finally
490+
{
491+
this._orm?.Aop.CommandAfterHandler?.Invoke(this._orm, new Aop.CommandAfterEventArgs(before, afterException, null));
492+
}
480493
}
481494
}
482495
finally

Providers/FreeSql.Provider.GBase/GBaseCodeFirst.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,20 @@ object LocalExecuteScalar(string db, string sql)
189189
cmd.CommandType = CommandType.Text;
190190
var before = new Aop.CommandBeforeEventArgs(cmd);
191191
this._orm?.Aop.CommandBeforeHandler?.Invoke(this._orm, before);
192-
return cmd.ExecuteScalar();
192+
Exception afterException = null;
193+
try
194+
{
195+
return cmd.ExecuteScalar();
196+
}
197+
catch (Exception ex)
198+
{
199+
afterException = ex;
200+
throw;
201+
}
202+
finally
203+
{
204+
this._orm?.Aop.CommandAfterHandler?.Invoke(this._orm, new Aop.CommandAfterEventArgs(before, afterException, null));
205+
}
193206
}
194207
}
195208
finally

Providers/FreeSql.Provider.MySql/MySqlCodeFirst.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,20 @@ object LocalExecuteScalar(string db, string sql)
395395
cmd.CommandType = CommandType.Text;
396396
var before = new Aop.CommandBeforeEventArgs(cmd);
397397
this._orm?.Aop.CommandBeforeHandler?.Invoke(this._orm, before);
398-
return cmd.ExecuteScalar();
398+
Exception afterException = null;
399+
try
400+
{
401+
return cmd.ExecuteScalar();
402+
}
403+
catch (Exception ex)
404+
{
405+
afterException = ex;
406+
throw;
407+
}
408+
finally
409+
{
410+
this._orm?.Aop.CommandAfterHandler?.Invoke(this._orm, new Aop.CommandAfterEventArgs(before, afterException, null));
411+
}
399412
}
400413
}
401414
finally

Providers/FreeSql.Provider.Odbc/MySql/OdbcMySqlCodeFirst.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,20 @@ object LocalExecuteScalar(string db, string sql)
385385
cmd.CommandType = CommandType.Text;
386386
var before = new Aop.CommandBeforeEventArgs(cmd);
387387
this._orm?.Aop.CommandBeforeHandler?.Invoke(this._orm, before);
388-
return cmd.ExecuteScalar();
388+
Exception afterException = null;
389+
try
390+
{
391+
return cmd.ExecuteScalar();
392+
}
393+
catch (Exception ex)
394+
{
395+
afterException = ex;
396+
throw;
397+
}
398+
finally
399+
{
400+
this._orm?.Aop.CommandAfterHandler?.Invoke(this._orm, new Aop.CommandAfterEventArgs(before, afterException, null));
401+
}
389402
}
390403
}
391404
finally

Providers/FreeSql.Provider.Odbc/SqlServer/OdbcSqlServerCodeFirst.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,20 @@ object LocalExecuteScalar(string db, string sql)
477477
cmd.CommandType = CommandType.Text;
478478
var before = new Aop.CommandBeforeEventArgs(cmd);
479479
this._orm?.Aop.CommandBeforeHandler?.Invoke(this._orm, before);
480-
return cmd.ExecuteScalar();
480+
Exception afterException = null;
481+
try
482+
{
483+
return cmd.ExecuteScalar();
484+
}
485+
catch (Exception ex)
486+
{
487+
afterException = ex;
488+
throw;
489+
}
490+
finally
491+
{
492+
this._orm?.Aop.CommandAfterHandler?.Invoke(this._orm, new Aop.CommandAfterEventArgs(before, afterException, null));
493+
}
481494
}
482495
}
483496
finally

Providers/FreeSql.Provider.SqlServer/SqlServerCodeFirst.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,20 @@ object LocalExecuteScalar(string db, string sql)
479479
cmd.CommandType = CommandType.Text;
480480
var before = new Aop.CommandBeforeEventArgs(cmd);
481481
this._orm?.Aop.CommandBeforeHandler?.Invoke(this._orm, before);
482-
return cmd.ExecuteScalar();
482+
Exception afterException = null;
483+
try
484+
{
485+
return cmd.ExecuteScalar();
486+
}
487+
catch (Exception ex)
488+
{
489+
afterException = ex;
490+
throw;
491+
}
492+
finally
493+
{
494+
this._orm?.Aop.CommandAfterHandler?.Invoke(this._orm, new Aop.CommandAfterEventArgs(before, afterException, null));
495+
}
483496
}
484497
}
485498
finally

0 commit comments

Comments
 (0)