Developer 02 72f735272f feat(Repository): Add and implement ReadOrDefaultAsync method.
- add read method can map for each
2025-04-22 23:04:11 +02:00

25 lines
809 B
C#

using AutoMapper;
using DigitalData.Core.Abstractions.Infrastructure;
namespace DigitalData.Core.Infrastructure.AutoMapper;
public class EntityAutoMapper<TEntity> : IEntityMapper<TEntity>
{
private readonly IMapper _rootMapper;
public EntityAutoMapper(IMapper rootMapper)
{
_rootMapper = rootMapper;
}
public TDto Map<TDto>(TEntity entity) => _rootMapper.Map<TDto>(entity);
public IEnumerable<TDto> Map<TDto>(IEnumerable<TEntity> entities) => _rootMapper.Map<IEnumerable<TDto>>(entities);
public TEntity Map<TDto>(TDto dto) => _rootMapper.Map<TEntity>(dto);
public IEnumerable<TEntity> Map<TDto>(IEnumerable<TDto> dtos) => _rootMapper.Map<IEnumerable<TEntity>>(dtos);
public TEntity Map<TDto>(TDto dto, TEntity entity) => _rootMapper.Map(dto, entity);
}