开发者

Disable default mapping convention for automapper

HI,

I am using autommaper in my app and for now I have one problem. When I use ConstructUsing method for specify constructor to map object, after that Automapper copy all other fields by default convention. But I don't need that. How I can set, that Mapper should use JUST constructor without c开发者_如何学运维opy anything else? Or the only way is to write custom Converter.


Use .ForAllMembers(opt => opt.Ignore()) to avoid additional mapping. Only method call will be performed in this case.


The converter is the way to go, it's designed to not do the other copying. It also takes a Func < TSource, TDestination > , so you should be able to just swap out the method you're calling in the configuration from ConstructUsing to ConvertUsing.


If you want disable mapping for most of properties you can use .ForAllOtherMembers(opt => opt.Ignore())

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜