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

时光怂恿深爱的人放手 提交于 2019-12-07 15:08:29

问题


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

where defs is array of Def (Def[])

how to map?


回答1:


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!!!



来源:https://stackoverflow.com/questions/2191768/how-to-map-single-object-of-type-x-to-array-of-object-of-type-y-using-automapper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!