Add CancellationToken to ExecuteDynamicSqlAsync method
The ExecuteDynamicSqlAsync extension for IRecDbContext now accepts an optional CancellationToken, which is passed to all async database operations to support cancellation. Also added a TODO to move this method to Common.Infrastructure in the future.
This commit is contained in:
@@ -29,7 +29,8 @@ public interface IRecDbContext
|
|||||||
|
|
||||||
public static class RecDbContextSaveExtensions
|
public static class RecDbContextSaveExtensions
|
||||||
{
|
{
|
||||||
public static async Task<string> ExecuteDynamicSqlAsync(this IRecDbContext context, string sql)
|
//TODO: Once it is finalized, move it to Common.Infrastructure
|
||||||
|
public static async Task<string> ExecuteDynamicSqlAsync(this IRecDbContext context, string sql, CancellationToken cancel = default)
|
||||||
{
|
{
|
||||||
var result = new List<Dictionary<string, object?>>();
|
var result = new List<Dictionary<string, object?>>();
|
||||||
|
|
||||||
@@ -37,10 +38,10 @@ public static class RecDbContextSaveExtensions
|
|||||||
|
|
||||||
command.CommandText = sql;
|
command.CommandText = sql;
|
||||||
|
|
||||||
await context.Database.OpenConnectionAsync();
|
await context.Database.OpenConnectionAsync(cancel);
|
||||||
|
|
||||||
using var reader = await command.ExecuteReaderAsync();
|
using var reader = await command.ExecuteReaderAsync(cancel);
|
||||||
while (await reader.ReadAsync())
|
while (await reader.ReadAsync(cancel))
|
||||||
{
|
{
|
||||||
var row = new Dictionary<string, object?>();
|
var row = new Dictionary<string, object?>();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user