Предположим, у нас есть следующая сущность и DTO:
Код: Выделить всё
public class MyEntity
{
public DateTime DateCreation { get; set; }
}
public class MyDto
{
public string DateCreation { get; set; }
}
Код: Выделить всё
using AutoMapper;
public class MyProfile : Profile
{
public MyProfile()
{
CreateMap()
.ForMember(dest => dest.DateCreation,
opt => opt.MapFrom(src => src.DateCreation.ToString("yyyy-MM-dd")));
}
}
Код: Выделить всё
var entity = new MyEntity { DateCreation = DateTime.Now };
var dto = mapper.Map(entity);
Console.WriteLine(dto.DateCreation);
Код: Выделить всё
// Outputs: "2026-01-29"
Код: Выделить всё
// Outputs: "2026-01-29 00:00:00"
Подробнее здесь: https://stackoverflow.com/questions/798 ... ng-automap
Мобильная версия