Skip to content

Instantly share code, notes, and snippets.

View clement911's full-sized avatar

Clement Gutel clement911

View GitHub Profile
@clement911
clement911 / 1_DbContextExtension.cs
Last active January 11, 2025 21:22
Record DB commands generated by EF core queries
public static IReadOnlyCollection<DbBatchCommand> RecordCommands<TContext, TResult>(this TContext dbCtx, params Func<TContext, TResult>[] getResults) where TContext : DbContext
{
using (RecordCommandsScope.StartNew())
{
foreach (var getResult in getResults)
getResult(dbCtx);
return RecordCommandsScope.Current.RecordedCommands;
}
}