Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to map single object of type x to array of object of type y using automapper

Mapper.CreateMap<A, B>()
      .ForMember(dest => dest.defs, opt => opt.MapFrom(origin => origin.abc));

where defs is array of Def (Def[])

how to map?

like image 330
Miral Avatar asked Nov 15 '25 10:11

Miral


1 Answers

Mapper.CreateMap<A, B>()
      .ForMember(dest => dest.defs, opt => opt.MapFrom(origin => new[]{ origin.abc }));

destination property is array of Def and so the source requries array of something, that's how automapper understands...

this works!!!

like image 102
Miral Avatar answered Nov 17 '25 08:11

Miral



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!