Add raw SQL support to repository interfaces and DI
Extended IRepository interfaces and DbRepository implementation to support raw and interpolated SQL query execution (sync/async) and querying. Updated DependencyInjection to allow registration of default repository implementations. Added Microsoft.EntityFrameworkCore.Abstractions as a dependency. Performed minor refactoring and cleanup.
This commit is contained in:
@@ -23,12 +23,22 @@ namespace DigitalData.Core.Infrastructure
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public int ExecuteSqlRaw([NotParameterized] string sql, params object[] parameters)
|
||||
public Task<int> ExecuteQueryRawAsync([NotParameterized] string sql, IEnumerable<object> parameters, CancellationToken cancel = default)
|
||||
{
|
||||
return Context.Database.ExecuteSqlRawAsync(sql, parameters, cancel);
|
||||
}
|
||||
|
||||
public Task<int> ExecuteQueryInterpolatedAsync(FormattableString sql, CancellationToken cancel = default)
|
||||
{
|
||||
return Context.Database.ExecuteSqlInterpolatedAsync(sql, cancel);
|
||||
}
|
||||
|
||||
public int ExecuteQueryRaw([NotParameterized] string sql, params object[] parameters)
|
||||
{
|
||||
return Context.Database.ExecuteSqlRaw(sql, parameters);
|
||||
}
|
||||
|
||||
public int ExecuteSqlInterpolated(FormattableString sql)
|
||||
public int ExecuteQueryInterpolated(FormattableString sql)
|
||||
{
|
||||
return Context.Database.ExecuteSqlInterpolated(sql);
|
||||
}
|
||||
@@ -57,11 +67,6 @@ namespace DigitalData.Core.Infrastructure
|
||||
Mapper = mapper;
|
||||
}
|
||||
|
||||
public IQueryable<TEntity> Sql([NotParameterized] string sql, params object[] parameters)
|
||||
{
|
||||
return Entities.FromSqlRaw(sql, parameters);
|
||||
}
|
||||
|
||||
#region Create
|
||||
public virtual async Task<TEntity> CreateAsync(TEntity entity, CancellationToken cancel = default)
|
||||
{
|
||||
@@ -95,6 +100,10 @@ namespace DigitalData.Core.Infrastructure
|
||||
#region Read
|
||||
public virtual IQueryable<TEntity> Query => Entities.AsNoTracking();
|
||||
|
||||
public IQueryable<TEntity> QueryRaw([NotParameterized] string sql, params object[] parameters) => Entities.FromSqlRaw(sql, parameters);
|
||||
|
||||
public IQueryable<TEntity> QueryInterpolated([NotParameterized] FormattableString sql) => Entities.FromSqlInterpolated(sql);
|
||||
|
||||
public virtual IQueryable<TEntity> Where(Expression<Func<TEntity, bool>> expression) => Entities.AsNoTracking().Where(expression);
|
||||
|
||||
public virtual IEnumerable<TEntity> GetAll() => Entities.AsNoTracking().ToList();
|
||||
|
||||
Reference in New Issue
Block a user