From ee5668a5cbf02d3f5d3fd0db6edd14216ab8080a Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Mon, 9 Sep 2024 17:44:18 +0200 Subject: [PATCH] feat: ReadAll-Methode in ICRUDRepository und CRUDRepository implementieren MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ReadAll-Methode zur ICRUDRepository-Schnittstelle hinzugefügt, um die Abfrage aller Entitäten zu ermöglichen. - ReadAll-Methode in der CRUDRepository-Klasse implementiert, um IQueryable für weitere Abfragen und Filterung bereitzustellen. --- .../Infrastructure/ICRUDRepository.cs | 10 ++++++++++ DigitalData.Core.Infrastructure/CRUDRepository.cs | 12 +++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/DigitalData.Core.Abstractions/Infrastructure/ICRUDRepository.cs b/DigitalData.Core.Abstractions/Infrastructure/ICRUDRepository.cs index 4223d82..c8355e9 100644 --- a/DigitalData.Core.Abstractions/Infrastructure/ICRUDRepository.cs +++ b/DigitalData.Core.Abstractions/Infrastructure/ICRUDRepository.cs @@ -21,6 +21,16 @@ /// The entity found, or null if no entity is found. Task ReadByIdAsync(TId id); + /// + /// Retrieves all entities of type from the repository. + /// + /// + /// This method returns an that represents all entities in the repository. + /// The result is an IQueryable that allows for further querying and filtering to be applied by the caller. + /// + /// An containing all entities of type in the repository. + protected IQueryable ReadAll(); + /// /// Retrieves all entities from the repository. /// diff --git a/DigitalData.Core.Infrastructure/CRUDRepository.cs b/DigitalData.Core.Infrastructure/CRUDRepository.cs index bde0e2a..f1688d9 100644 --- a/DigitalData.Core.Infrastructure/CRUDRepository.cs +++ b/DigitalData.Core.Infrastructure/CRUDRepository.cs @@ -49,11 +49,21 @@ namespace DigitalData.Core.Infrastructure /// The entity found, or null if no entity is found with the specified identifier. public virtual async Task ReadByIdAsync(TId id) => await _dbSet.FindAsync(id); + /// + /// Retrieves all entities of type from the database. + /// + /// + /// This method returns an of all entities in the database. + /// The result is not tracked by the context, which improves performance when you only need to read data without making modifications. + /// + /// An containing all entities of type . + protected virtual IQueryable ReadAll() => _dbSet.AsNoTracking(); + /// /// Asynchronously retrieves all entities of type TEntity. /// /// An enumerable of all entities in the database. - public virtual async Task> ReadAllAsync() => await _dbSet.ToListAsync(); + public virtual async Task> ReadAllAsync() => await ReadAll().ToListAsync(); /// /// Asynchronously updates an existing entity in the repository.