From 144178a504a84dc45a8fe729f887fb59b45ac524 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Thu, 18 Dec 2025 21:54:22 +0100 Subject: [PATCH] Add async SQL execution methods to DbRepository Added `ExecuteSqlRawAsync` and `ExecuteSqlInterpolatedAsync` methods to the `DbRepository` class for asynchronous SQL execution. Updated the `System.Linq` namespace import to support LINQ operations. Simplified conditional compilation directives by consistently enclosing the class declaration in braces `{}` across frameworks. Adjusted closing braces to align with the updated structure. --- .../DbRepository.cs | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/DigitalData.Core.Infrastructure/DbRepository.cs b/DigitalData.Core.Infrastructure/DbRepository.cs index 6771a73..7d559ed 100644 --- a/DigitalData.Core.Infrastructure/DbRepository.cs +++ b/DigitalData.Core.Infrastructure/DbRepository.cs @@ -13,12 +13,7 @@ using System.Threading.Tasks; #endif namespace DigitalData.Core.Infrastructure -#if NET - ; -#elif NETFRAMEWORK - { -#endif - +{ public class DbRepository where TDbContext : DbContext { protected internal readonly TDbContext Context; @@ -28,6 +23,16 @@ namespace DigitalData.Core.Infrastructure Context = context; } + public Task ExecuteSqlRawAsync([NotParameterized] string sql, IEnumerable parameters, CancellationToken cancel = default) + { + return Context.Database.ExecuteSqlRawAsync(sql, parameters, cancel); + } + + public Task ExecuteSqlInterpolatedAsync(FormattableString sql, CancellationToken cancel = default) + { + return Context.Database.ExecuteSqlInterpolatedAsync(sql, cancel); + } + public int ExecuteSqlRaw([NotParameterized] string sql, params object[] parameters) { return Context.Database.ExecuteSqlRaw(sql, parameters); @@ -155,6 +160,4 @@ namespace DigitalData.Core.Infrastructure public virtual IQueryable ReadOnly() => Entities.AsNoTracking(); #endregion } -#if NETFRAMEWORK - } -#endif \ No newline at end of file +} \ No newline at end of file