remove ReadQuery
This commit is contained in:
@@ -33,8 +33,10 @@ public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbC
|
||||
return entities;
|
||||
}
|
||||
|
||||
public IReadQuery<TEntity> Read(params Expression<Func<TEntity, bool>>[] expressions) => new ReadQuery<TEntity>(Entities.AsNoTracking()).Where(expressions);
|
||||
|
||||
public IQueryable<TEntity> Read() => Entities.AsQueryable();
|
||||
|
||||
public IQueryable<TEntity> ReadOnly() => Entities.AsNoTracking();
|
||||
|
||||
public virtual async Task UpdateAsync<TDto>(TDto dto, Expression<Func<TEntity, bool>> expression, CancellationToken ct = default)
|
||||
{
|
||||
var entities = await Entities.Where(expression).ToListAsync(ct);
|
||||
@@ -59,29 +61,4 @@ public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbC
|
||||
|
||||
await Context.SaveChangesAsync(ct);
|
||||
}
|
||||
|
||||
#region Obsolete
|
||||
[Obsolete("Use Read-method returning IReadQuery<TEntity> instead.")]
|
||||
public virtual async Task<IEnumerable<TEntity>> ReadAllAsync(Expression<Func<TEntity, bool>>? expression = null, CancellationToken ct = default)
|
||||
=> expression is null
|
||||
? await Entities.AsNoTracking().ToListAsync(ct)
|
||||
: await Entities.AsNoTracking().Where(expression).ToListAsync(ct);
|
||||
|
||||
[Obsolete("Use Read-method returning IReadQuery<TEntity> instead.")]
|
||||
public virtual async Task<TEntity?> ReadOrDefaultAsync(Expression<Func<TEntity, bool>> expression, bool single = true, CancellationToken ct = default)
|
||||
=> single
|
||||
? await Entities.AsNoTracking().Where(expression).SingleOrDefaultAsync(ct)
|
||||
: await Entities.AsNoTracking().Where(expression).FirstOrDefaultAsync(ct);
|
||||
|
||||
[Obsolete("Use Read-method returning IReadQuery<TEntity> instead.")]
|
||||
public virtual async Task<IEnumerable<TDto>> ReadAllAsync<TDto>(Expression<Func<TEntity, bool>>? expression = null, CancellationToken ct = default)
|
||||
=> Mapper.Map<TDto>(await ReadAllAsync(expression, ct));
|
||||
|
||||
[Obsolete("Use Read-method returning IReadQuery<TEntity> instead.")]
|
||||
public virtual async Task<TDto?> ReadOrDefaultAsync<TDto>(Expression<Func<TEntity, bool>> expression, bool single = true, CancellationToken ct = default)
|
||||
{
|
||||
var entity = await ReadOrDefaultAsync(expression, single, ct);
|
||||
return entity is null ? default : Mapper.Map<TDto>(entity);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
using DigitalData.Core.Abstraction.Application.Repository;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace DigitalData.Core.Infrastructure;
|
||||
|
||||
public sealed record ReadQuery<TEntity> : IReadQuery<TEntity>
|
||||
{
|
||||
private IQueryable<TEntity> _query;
|
||||
|
||||
internal ReadQuery(IQueryable<TEntity> queryable)
|
||||
{
|
||||
_query = queryable;
|
||||
}
|
||||
|
||||
public TEntity First() => _query.First();
|
||||
|
||||
public Task<TEntity> FirstAsync(CancellationToken cancellation = default) => _query.FirstAsync(cancellation);
|
||||
|
||||
public TEntity? FirstOrDefault() => _query.FirstOrDefault();
|
||||
|
||||
|
||||
public Task<TEntity?> FirstOrDefaultAsync(CancellationToken cancellation = default) => _query.FirstOrDefaultAsync(cancellation);
|
||||
|
||||
|
||||
public TEntity Single() => _query.Single();
|
||||
|
||||
|
||||
public Task<TEntity> SingleAsync(CancellationToken cancellation = default) => _query.SingleAsync(cancellation);
|
||||
|
||||
|
||||
public TEntity? SingleOrDefault() => _query.SingleOrDefault();
|
||||
|
||||
|
||||
public Task<TEntity?> SingleOrDefaultAsync(CancellationToken cancellation = default) => _query.SingleOrDefaultAsync(cancellation);
|
||||
|
||||
|
||||
public IEnumerable<TEntity> ToList() => _query.ToList();
|
||||
|
||||
|
||||
public async Task<IEnumerable<TEntity>> ToListAsync(CancellationToken cancellation = default) => await _query.ToListAsync(cancellation);
|
||||
|
||||
public IReadQuery<TEntity> Where(Expression<Func<TEntity, bool>> expression)
|
||||
{
|
||||
_query = _query.Where(expression);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user