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.
This commit is contained in:
@@ -13,12 +13,7 @@ using System.Threading.Tasks;
|
||||
#endif
|
||||
|
||||
namespace DigitalData.Core.Infrastructure
|
||||
#if NET
|
||||
;
|
||||
#elif NETFRAMEWORK
|
||||
{
|
||||
#endif
|
||||
|
||||
{
|
||||
public class DbRepository<TDbContext> where TDbContext : DbContext
|
||||
{
|
||||
protected internal readonly TDbContext Context;
|
||||
@@ -28,6 +23,16 @@ namespace DigitalData.Core.Infrastructure
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public Task<int> ExecuteSqlRawAsync([NotParameterized] string sql, IEnumerable<object> parameters, CancellationToken cancel = default)
|
||||
{
|
||||
return Context.Database.ExecuteSqlRawAsync(sql, parameters, cancel);
|
||||
}
|
||||
|
||||
public Task<int> 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<TEntity> ReadOnly() => Entities.AsNoTracking();
|
||||
#endregion
|
||||
}
|
||||
#if NETFRAMEWORK
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user