Skip to content

Commit

Permalink
Merge pull request #805 from medkg15/future-dbcommand-interception
Browse files Browse the repository at this point in the history
Add extension points before and after a Future query is run.
  • Loading branch information
JonathanMagnan committed Aug 8, 2024
2 parents 4784488 + f0222ac commit 544ade2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/shared/Z.EF.Plus.QueryFuture.Shared/QueryFutureBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public void ExecuteQueries()

using (command)
{
QueryFutureManager.OnBatchExecuting?.Invoke(command);
#if EF5
using (var reader = command.ExecuteReader())
{
Expand Down Expand Up @@ -213,6 +214,7 @@ public void ExecuteQueries()
}
}
#endif
QueryFutureManager.OnBatchExecuted?.Invoke(command);
}
}
finally
Expand Down
16 changes: 16 additions & 0 deletions src/shared/Z.EF.Plus.QueryFuture.Shared/QueryFutureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

using System.Runtime.CompilerServices;
using Z.EntityFramework.Extensions;
using System;
using System.Data.Common;

#if NET45 || EFCORE

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

/// <summary>Gets or sets a delegate to be invoked directly before executing the batch DbCommand.</summary>
/// <remarks>
/// This delegate is only invoked when queries are actually executed as a batch containing multiple queries.
/// i.e. When AllowQueryBatch=false or only a single query is pending, this delegate is not invoked.
/// </remarks>
public static Action<DbCommand> OnBatchExecuting { get; set; } = null;

/// <summary>Gets or sets a delegate to be invoked directly after executing the batch DbCommand.</summary>
/// <remarks>
/// This delegate is only invoked when queries are actually executed as a batch containing multiple queries.
/// i.e. When AllowQueryBatch=false or only a single query is pending, this delegate is not invoked.
/// </remarks>
public static Action<DbCommand> OnBatchExecuted { get; set; } = null;

/// <summary>Gets or sets the weak table used to cache future batch associated to a context.</summary>
/// <value>The weak table used to cache future batch associated to a context.</value>
#if EF5 || EF6
Expand Down

0 comments on commit 544ade2

Please sign in to comment.