Skip to content

Commit 544ade2

Browse files
Merge pull request #805 from medkg15/future-dbcommand-interception
Add extension points before and after a Future query is run.
2 parents 4784488 + f0222ac commit 544ade2

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-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: 16 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,20 @@ 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+
/// <remarks>
60+
/// This delegate is only invoked when queries are actually executed as a batch containing multiple queries.
61+
/// i.e. When AllowQueryBatch=false or only a single query is pending, this delegate is not invoked.
62+
/// </remarks>
63+
public static Action<DbCommand> OnBatchExecuting { get; set; } = null;
64+
65+
/// <summary>Gets or sets a delegate to be invoked directly after executing the batch DbCommand.</summary>
66+
/// <remarks>
67+
/// This delegate is only invoked when queries are actually executed as a batch containing multiple queries.
68+
/// i.e. When AllowQueryBatch=false or only a single query is pending, this delegate is not invoked.
69+
/// </remarks>
70+
public static Action<DbCommand> OnBatchExecuted { get; set; } = null;
71+
5672
/// <summary>Gets or sets the weak table used to cache future batch associated to a context.</summary>
5773
/// <value>The weak table used to cache future batch associated to a context.</value>
5874
#if EF5 || EF6

0 commit comments

Comments
 (0)