Add mapping methods to IRepository and DbRepository

Updated the `IRepository<TEntity>` interface to include two new mapping methods: `Map<TSource>(TSource source)` and `Map<TDto>(TEntity source)`.

Implemented these methods in the `DbRepository<TDbContext, TEntity>` class, utilizing a `Mapper` for conversions between source types and entity types, as well as between entity types and DTOs.
This commit is contained in:
Developer 02 2025-04-17 13:01:51 +02:00
parent 0c529b199b
commit 6916e169b1
2 changed files with 8 additions and 0 deletions

View File

@ -13,4 +13,8 @@ public interface IRepository<TEntity>
public Task UpdateAsync<TUpdate>(TUpdate update, Expression<Func<TEntity, bool>> expression, CancellationToken ct = default); public Task UpdateAsync<TUpdate>(TUpdate update, Expression<Func<TEntity, bool>> expression, CancellationToken ct = default);
public Task DeleteAsync<TDto>(Expression<Func<TEntity, bool>> expression, CancellationToken ct = default); public Task DeleteAsync<TDto>(Expression<Func<TEntity, bool>> expression, CancellationToken ct = default);
public TEntity Map<TSource>(TSource source);
public TDto Map<TDto>(TEntity source);
} }

View File

@ -63,4 +63,8 @@ public class DbRepository<TDbContext, TEntity> : IRepository<TEntity> where TDbC
await Context.SaveChangesAsync(ct); await Context.SaveChangesAsync(ct);
} }
public TEntity Map<TSource>(TSource source) => Mapper.Map<TEntity>(source);
public TDto Map<TDto>(TEntity entity) => Mapper.Map<TDto>(entity);
} }