From 406a41b91f90a65789c37bebf8f030862563ceb7 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Wed, 11 Sep 2024 10:52:56 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20CountAsync-Methode=20zum=20Repository-I?= =?UTF-8?q?nterface=20und=20zur=20Implementierung=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Eine neue asynchrone CountAsync-Methode wurde zum Repository-Interface und zur Implementierung hinzugefügt. Diese Methode zählt die Anzahl der Entitäten mit einer bestimmten ID in der Datenbank. --- .../Infrastructure/ICRUDRepository.cs | 12 ++++++++++++ DigitalData.Core.Infrastructure/CRUDRepository.cs | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/DigitalData.Core.Abstractions/Infrastructure/ICRUDRepository.cs b/DigitalData.Core.Abstractions/Infrastructure/ICRUDRepository.cs index 3acf834..c5562ff 100644 --- a/DigitalData.Core.Abstractions/Infrastructure/ICRUDRepository.cs +++ b/DigitalData.Core.Abstractions/Infrastructure/ICRUDRepository.cs @@ -46,5 +46,17 @@ /// /// The total number of entities in the repository. Task CountAsync(); + + /// + /// Asynchronously counts the number of entities in the repository that match a specific identifier. + /// + /// The identifier of the entities to count. + /// The number of entities with the specified identifier. + /// + /// This method provides a count of entities in the database that match the given identifier. + /// If there are multiple entities with the same identifier, they will all be counted. + /// The default implementation assumes that the identifier is unique for each entity. + /// + Task CountAsync(TId id); } } \ No newline at end of file diff --git a/DigitalData.Core.Infrastructure/CRUDRepository.cs b/DigitalData.Core.Infrastructure/CRUDRepository.cs index 2a1bdd0..93de22e 100644 --- a/DigitalData.Core.Infrastructure/CRUDRepository.cs +++ b/DigitalData.Core.Infrastructure/CRUDRepository.cs @@ -96,5 +96,17 @@ namespace DigitalData.Core.Infrastructure /// /// The total number of entities in the repository. public virtual async Task CountAsync() => await _dbSet.CountAsync(); + + /// + /// Asynchronously counts the number of entities in the repository that match a specific identifier. + /// + /// The identifier of the entities to count. + /// The number of entities with the specified identifier. + /// + /// This method provides a count of entities in the database that match the given identifier. + /// If there are multiple entities with the same identifier, they will all be counted. + /// The default implementation assumes that the identifier is unique for each entity. + /// + public virtual async Task CountAsync(TId id) => await _dbSet.Where(e => e.Id!.Equals(id)).CountAsync(); } } \ No newline at end of file