Skip to content

Commit 26b1453

Browse files
committed
Add extension points before and after a Future query is run.
1 parent 4784488 commit 26b1453

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/shared/Z.EF.Plus.QueryFuture.Shared/QueryFutureBatch.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ public void ExecuteQueries()
183183

184184
using (command)
185185
{
186+
QueryFutureManager.OnBatchExecuting?.Invoke(command);
186187
#if EF5
187188
using (var reader = command.ExecuteReader())
188189
{
@@ -213,6 +214,7 @@ public void ExecuteQueries()
213214
}
214215
}
215216
#endif
217+
QueryFutureManager.OnBatchExecuted?.Invoke(command);
216218
}
217219
}
218220
finally

src/shared/Z.EF.Plus.QueryFuture.Shared/QueryFutureManager.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
using System.Runtime.CompilerServices;
99
using Z.EntityFramework.Extensions;
10+
using System;
11+
using System.Data.Common;
1012

1113
#if NET45 || EFCORE
1214

@@ -53,6 +55,12 @@ static QueryFutureManager()
5355
/// <value>True if allow query batch, false if not.</value>
5456
public static bool AllowQueryBatch { get; set; } = true;
5557

58+
/// <summary>Gets or sets a delegate to be invoked directly before executing the batch DbCommand.</summary>
59+
public static Action<DbCommand> OnBatchExecuting { get; set; } = cmd => { };
60+
61+
/// <summary>Gets or sets a delegate to be invoked directly after executing the batch DbCommand.</summary>
62+
public static Action<DbCommand> OnBatchExecuted { get; set; } = cmd => { };
63+
5664
/// <summary>Gets or sets the weak table used to cache future batch associated to a context.</summary>
5765
/// <value>The weak table used to cache future batch associated to a context.</value>
5866
#if EF5 || EF6

0 commit comments

Comments
 (0)