AutoMapper Map If Not Null, Otherwise Custom Convert

前端 未结 4 1200
伪装坚强ぢ
伪装坚强ぢ 2021-02-02 08:29

Here\'s my code:

Mapper.CreateMap()
   .ForMember(dest => dest.Bar, opt => opt.MapFrom(src => src.Bar == null ? new BarViewModel() : sr         


        
4条回答
  •  误落风尘
    2021-02-02 09:03

    Now you can use .NullSubstitute() to replace NULL value to some custom value in Automapper, e.g.:

    CreateMap()
                        .ForMember(d => d.myDate, o => o.NullSubstitute(new DateTime(2017,12,12)));
    

提交回复
热议问题