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:
parent
0c529b199b
commit
6916e169b1
@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user