开发者

Using DynamicMap() and ignore null source value

开发者 https://www.devze.com 2023-01-15 20:11 出处:网络
I\'m using Mapper.DynamicMap() inside a generic method and would like to, without using .CreateMap(), ignore some any source values that are null. Is this even poss开发者_C百科ible?If you want all sou

I'm using Mapper.DynamicMap() inside a generic method and would like to, without using .CreateMap(), ignore some any source values that are null. Is this even poss开发者_C百科ible?


If you want all source properties with null values to be ignored you could use:

Mapper.CreateMap<SourceType, DestinationType>()
                    .ForAllMembers(opt => opt.Condition(srs => !srs.IsSourceValueNull));

Otherwise, you can do something similar for each member. This will get quit tedious if there are a large number of properties.


I solved it with DataMember property in destination type [DataMember(EmitDefaultValue = false)] add this in the destination DTO

0

精彩评论

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