c# - Automapper not mapping different property names -
i have dto class called cardatadto
2 properties named below:
public decimal fueltanksize { get; set; } public decimal carengineoutput { get; set; }
i using dapper
, can see data getting returned , mapped properties in dto expected.
i using webapi return data ui - properties on ui named differently below in class called cardata
public decimal size { get; set; } public decimal engineoutput { get; set; }
so attempting use automapper map these properties below - have automapper config class initialize method called in application_start
in 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 getting data in webapi method db list of data , returning below:
var cardata = _myservice.getallcardata().tolist(); //error checking etc removed brevity return mapper.map<ienumerable<cardatadto>, ienumerable<cardata>>(cardata);
with breakpoint set on cardata line can see fueltanksize , carengineoutput have values db expected - when run in postman values size , engineoutput 0
Comments
Post a Comment