I have a DTO class called CarDataDTO
with two properties named as below:
public decimal FuelTankSize { get; set; }
public decimal CarEngineOutput { get; set; }
I am using Dapper
and I can see the Data getting returned and mapped to the properties in the DTO as expected.
I am using WebAPI to return Data to UI - the properties on the UI are named differently as below in a class called CarData
public decimal Size { get; set; }
public decimal EngineOutput { get; set; }
So I am attempting to use Automapper to map these properties as below - I have an Automapper config class with an Initialize method which is called in Application_Start
in the Global.asax.cs
config.CreateMap<CarData, CarDataDTO>()
.ForMember(dest => dest.FuelTankSize, opt => opt.MapFrom(src => src.Size))
.ForMember(dest => dest.CarEngineOutput, opt => opt.MapFrom(src => src.EngineOutput))
.ReverseMap();
I am then getting then Data in the WebAPI method from the DB where it is a list of data and returning it as below:
var carData = _myService.GetAllCarData().ToList();
//error checking etc removed for brevity
return Mapper.Map<IEnumerable<CarDataDTO>, IEnumerable<CarData>>(carData);
With a breakpoint set on the carData line I can see that FuelTankSize and CarEngineOutput have values from the DB as expected - but when I run in PostMan the values for Size and EngineOutput are 0