From 048ba35804fe9155c48dd4df517014ca0467bdcf Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 21 Aug 2025 18:19:16 +0200 Subject: [PATCH] remove ReadQuery --- .../Repository/Extensions.cs | 14 --- .../Repository/IReadQuery.cs | 85 ------------------- .../Repository/IRepository.cs | 18 +--- .../Repository/RepositoryExtensions.cs | 14 --- ...italData.Core.Exceptions.Middleware.csproj | 6 +- .../DbRepository.cs | 31 +------ DigitalData.Core.Infrastructure/ReadQuery.cs | 48 ----------- 7 files changed, 10 insertions(+), 206 deletions(-) delete mode 100644 DigitalData.Core.Abstraction.Application/Repository/IReadQuery.cs delete mode 100644 DigitalData.Core.Abstraction.Application/Repository/RepositoryExtensions.cs delete mode 100644 DigitalData.Core.Infrastructure/ReadQuery.cs diff --git a/DigitalData.Core.Abstraction.Application/Repository/Extensions.cs b/DigitalData.Core.Abstraction.Application/Repository/Extensions.cs index 3b0f3d9..9d86ac5 100644 --- a/DigitalData.Core.Abstraction.Application/Repository/Extensions.cs +++ b/DigitalData.Core.Abstraction.Application/Repository/Extensions.cs @@ -17,18 +17,4 @@ public static class Extensions return repository.CreateAsync(entities, ct); } #endregion - - #region Read - public static async Task ReadFirstOrDefaultAsync(this IRepository repository, Expression>? expression = null) - => (await repository.ReadAllAsync(expression)).FirstOrDefault(); - - public static async Task ReadFirstAsync(this IRepository repository, Expression>? expression = null) - => (await repository.ReadAllAsync(expression)).First(); - - public static async Task ReadSingleOrDefaultAsync(this IRepository repository, Expression>? expression = null) - => (await repository.ReadAllAsync(expression)).SingleOrDefault(); - - public static async Task ReadSingleAsync(this IRepository repository, Expression>? expression = null) - => (await repository.ReadAllAsync(expression)).Single(); - #endregion } diff --git a/DigitalData.Core.Abstraction.Application/Repository/IReadQuery.cs b/DigitalData.Core.Abstraction.Application/Repository/IReadQuery.cs deleted file mode 100644 index b560722..0000000 --- a/DigitalData.Core.Abstraction.Application/Repository/IReadQuery.cs +++ /dev/null @@ -1,85 +0,0 @@ -using System.Linq.Expressions; - -namespace DigitalData.Core.Abstraction.Application.Repository; - -/// -/// Provides methods for executing common queries on a given entity type. -/// This interface abstracts away the direct usage of ORM libraries (such as Entity Framework) for querying data -/// and provides asynchronous and synchronous operations for querying a collection or single entity. -/// -/// The type of the entity being queried. -public interface IReadQuery -{ - /// - /// Adds a filter to the query using the specified predicate expression. - /// This method allows chaining multiple filter conditions to refine the query results. - /// - /// An expression that defines the filter condition for the entity. - /// The current instance with the applied filter. - public IReadQuery Where(Expression> expression); - - /// - /// Asynchronously retrieves the first entity or a default value if no entity is found. - /// - /// A to observe while waiting for the task to complete. - /// A task that represents the asynchronous operation. The task result contains the entity or a default value. - public Task FirstOrDefaultAsync(CancellationToken cancellation = default); - - /// - /// Asynchronously retrieves a single entity or a default value if no entity is found. - /// - /// A to observe while waiting for the task to complete. - /// A task that represents the asynchronous operation. The task result contains the entity or a default value. - public Task SingleOrDefaultAsync(CancellationToken cancellation = default); - - /// - /// Asynchronously retrieves a list of entities. - /// - /// A to observe while waiting for the task to complete. - /// A task that represents the asynchronous operation. The task result contains the list of entities. - public Task> ToListAsync(CancellationToken cancellation = default); - - /// - /// Asynchronously retrieves the first entity. Throws an exception if no entity is found. - /// - /// A to observe while waiting for the task to complete. - /// A task that represents the asynchronous operation. The task result contains the first entity. - public Task FirstAsync(CancellationToken cancellation = default); - - /// - /// Asynchronously retrieves a single entity. Throws an exception if no entity is found. - /// - /// A to observe while waiting for the task to complete. - /// A task that represents the asynchronous operation. The task result contains the single entity. - public Task SingleAsync(CancellationToken cancellation = default); - - /// - /// Synchronously retrieves the first entity or a default value if no entity is found. - /// - /// The first entity or a default value. - public TEntity? FirstOrDefault(); - - /// - /// Synchronously retrieves a single entity or a default value if no entity is found. - /// - /// The single entity or a default value. - public TEntity? SingleOrDefault(); - - /// - /// Synchronously retrieves a list of entities. - /// - /// The list of entities. - public IEnumerable ToList(); - - /// - /// Synchronously retrieves the first entity. Throws an exception if no entity is found. - /// - /// The first entity. - public TEntity First(); - - /// - /// Synchronously retrieves a single entity. Throws an exception if no entity is found. - /// - /// The single entity. - public TEntity Single(); -} \ No newline at end of file diff --git a/DigitalData.Core.Abstraction.Application/Repository/IRepository.cs b/DigitalData.Core.Abstraction.Application/Repository/IRepository.cs index 081ad0c..cd51800 100644 --- a/DigitalData.Core.Abstraction.Application/Repository/IRepository.cs +++ b/DigitalData.Core.Abstraction.Application/Repository/IRepository.cs @@ -10,23 +10,11 @@ public interface IRepository public Task> CreateAsync(IEnumerable entities, CancellationToken cancellation = default); - public IReadQuery Read(params Expression>[] expressions); + public IQueryable Read(); + + public IQueryable ReadOnly(); public Task UpdateAsync(TDto dto, Expression> expression, CancellationToken cancellation = default); public Task DeleteAsync(Expression> expression, CancellationToken cancellation = default); - - #region Obsolete - [Obsolete("Use Read-method returning IReadQuery instead.")] - public Task> ReadAllAsync(Expression>? expression = null, CancellationToken cancellation = default); - - [Obsolete("Use Read-method returning IReadQuery instead.")] - public Task ReadOrDefaultAsync(Expression> expression, bool single = true, CancellationToken cancellation = default); - - [Obsolete("Use Read-method returning IReadQuery instead.")] - public Task> ReadAllAsync(Expression>? expression = null, CancellationToken cancellation = default); - - [Obsolete("Use Read-method returning IReadQuery instead.")] - public Task ReadOrDefaultAsync(Expression> expression, bool single = true, CancellationToken cancellation = default); - #endregion } diff --git a/DigitalData.Core.Abstraction.Application/Repository/RepositoryExtensions.cs b/DigitalData.Core.Abstraction.Application/Repository/RepositoryExtensions.cs deleted file mode 100644 index e9efa5d..0000000 --- a/DigitalData.Core.Abstraction.Application/Repository/RepositoryExtensions.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Linq.Expressions; - -namespace DigitalData.Core.Abstraction.Application.Repository; - -public static class RepositoryExtensions -{ - public static IReadQuery Where(this IReadQuery query, params Expression>[] expressions) - { - foreach (var expression in expressions) - query = query.Where(expression); - - return query; - } -} \ No newline at end of file diff --git a/DigitalData.Core.Exceptions.Middleware/DigitalData.Core.Exceptions.Middleware.csproj b/DigitalData.Core.Exceptions.Middleware/DigitalData.Core.Exceptions.Middleware.csproj index 9feae0a..8f65cfd 100644 --- a/DigitalData.Core.Exceptions.Middleware/DigitalData.Core.Exceptions.Middleware.csproj +++ b/DigitalData.Core.Exceptions.Middleware/DigitalData.Core.Exceptions.Middleware.csproj @@ -17,9 +17,9 @@ http://git.dd:3000/AppStd/WebCoreModules.git False core_icon.png - 1.0.0 - 1.0.0 - 1.0.0 + 1.0.1 + 1.0.1 + 1.0.1 diff --git a/DigitalData.Core.Infrastructure/DbRepository.cs b/DigitalData.Core.Infrastructure/DbRepository.cs index ec3869c..031b2ed 100644 --- a/DigitalData.Core.Infrastructure/DbRepository.cs +++ b/DigitalData.Core.Infrastructure/DbRepository.cs @@ -33,8 +33,10 @@ public class DbRepository : IRepository where TDbC return entities; } - public IReadQuery Read(params Expression>[] expressions) => new ReadQuery(Entities.AsNoTracking()).Where(expressions); - + public IQueryable Read() => Entities.AsQueryable(); + + public IQueryable ReadOnly() => Entities.AsNoTracking(); + public virtual async Task UpdateAsync(TDto dto, Expression> expression, CancellationToken ct = default) { var entities = await Entities.Where(expression).ToListAsync(ct); @@ -59,29 +61,4 @@ public class DbRepository : IRepository where TDbC await Context.SaveChangesAsync(ct); } - - #region Obsolete - [Obsolete("Use Read-method returning IReadQuery instead.")] - public virtual async Task> ReadAllAsync(Expression>? 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 instead.")] - public virtual async Task ReadOrDefaultAsync(Expression> 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 instead.")] - public virtual async Task> ReadAllAsync(Expression>? expression = null, CancellationToken ct = default) - => Mapper.Map(await ReadAllAsync(expression, ct)); - - [Obsolete("Use Read-method returning IReadQuery instead.")] - public virtual async Task ReadOrDefaultAsync(Expression> expression, bool single = true, CancellationToken ct = default) - { - var entity = await ReadOrDefaultAsync(expression, single, ct); - return entity is null ? default : Mapper.Map(entity); - } - #endregion } \ No newline at end of file diff --git a/DigitalData.Core.Infrastructure/ReadQuery.cs b/DigitalData.Core.Infrastructure/ReadQuery.cs deleted file mode 100644 index 6ade520..0000000 --- a/DigitalData.Core.Infrastructure/ReadQuery.cs +++ /dev/null @@ -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 : IReadQuery -{ - private IQueryable _query; - - internal ReadQuery(IQueryable queryable) - { - _query = queryable; - } - - public TEntity First() => _query.First(); - - public Task FirstAsync(CancellationToken cancellation = default) => _query.FirstAsync(cancellation); - - public TEntity? FirstOrDefault() => _query.FirstOrDefault(); - - - public Task FirstOrDefaultAsync(CancellationToken cancellation = default) => _query.FirstOrDefaultAsync(cancellation); - - - public TEntity Single() => _query.Single(); - - - public Task SingleAsync(CancellationToken cancellation = default) => _query.SingleAsync(cancellation); - - - public TEntity? SingleOrDefault() => _query.SingleOrDefault(); - - - public Task SingleOrDefaultAsync(CancellationToken cancellation = default) => _query.SingleOrDefaultAsync(cancellation); - - - public IEnumerable ToList() => _query.ToList(); - - - public async Task> ToListAsync(CancellationToken cancellation = default) => await _query.ToListAsync(cancellation); - - public IReadQuery Where(Expression> expression) - { - _query = _query.Where(expression); - return this; - } -} \ No newline at end of file