feat(Repository): Add and implement ReadOrDefaultAsync method.

- add read method can map for each
This commit is contained in:
Developer 02
2025-04-22 23:04:11 +02:00
parent 304f5b7b4c
commit 72f735272f
8 changed files with 55 additions and 15 deletions

View File

@@ -20,15 +20,15 @@ public static class Extensions
#region Read
public static async Task<TEntity?> ReadFirstOrDefaultAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null)
=> (await repository.ReadAsync(expression)).FirstOrDefault();
=> (await repository.ReadAllAsync(expression)).FirstOrDefault();
public static async Task<TEntity> ReadFirstAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null)
=> (await repository.ReadAsync(expression)).First();
=> (await repository.ReadAllAsync(expression)).First();
public static async Task<TEntity?> ReadSingleOrDefaultAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null)
=> (await repository.ReadAsync(expression)).SingleOrDefault();
=> (await repository.ReadAllAsync(expression)).SingleOrDefault();
public static async Task<TEntity> ReadSingleAsync<TEntity>(this IRepository<TEntity> repository, Expression<Func<TEntity, bool>>? expression = null)
=> (await repository.ReadAsync(expression)).Single();
=> (await repository.ReadAllAsync(expression)).Single();
#endregion
}