Add QueryRaw and QueryInterpolated methods to repository
Added `QueryRaw` and `QueryInterpolated` methods to the `IRepository` interface for raw and interpolated SQL queries, conditionally compiled for the `NET` target framework. Removed the `Sql` method from `DbRepository` and replaced it with implementations of `QueryRaw` and `QueryInterpolated` using `Entities.FromSqlRaw` and `Entities.FromSqlInterpolated`. Updated the `Query` property in `DbRepository` to use `Entities.AsNoTracking()` for read-only queries.
This commit is contained in:
@@ -63,6 +63,16 @@ namespace DigitalData.Core.Abstraction.Application.Repository
|
||||
#endif
|
||||
IQueryable<TEntity> Query { get; }
|
||||
|
||||
#if NET
|
||||
public
|
||||
#endif
|
||||
IQueryable<TEntity> QueryRaw([NotParameterized] string sql, params object[] parameters);
|
||||
|
||||
#if NET
|
||||
public
|
||||
#endif
|
||||
IQueryable<TEntity> QueryInterpolated([NotParameterized] FormattableString sql);
|
||||
|
||||
#if NET
|
||||
public
|
||||
#endif
|
||||
|
||||
@@ -67,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)
|
||||
{
|
||||
@@ -105,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