ReverseMap with condition operator doesn't seem to work? Or is my syntax incorrect?

18 views
Skip to first unread message

John Stemper

unread,
Sep 14, 2016, 9:49:21 AM9/14/16
to AutoMapper-users

I'm trying to map an Entity Framework model to view model and back again so that if the view model has changes to a field it is mapped back to the entity but if the view model field is null it doesn't change the entities field value. My map config is currently this:

   cfg.CreateMap<Order, OrderVM>()
      .MaxDepth(4)
      .ReverseMap()
      .ForMember(d => d.BestTimeToCall,opt=>opt.Condition(src=>src.BestTimeToCall!=null));

In the above I want the BestTimeToCall field to always map from the order to the orderVM but I only want the BestTimeToCall value to map from the orderVM back to the order if the BestTimeToCall value is not null.

The mapping above does not work. What is the correct syntax to accomplish this?


Thanks

John

Michael Powell

unread,
Sep 14, 2016, 8:51:49 PM9/14/16
to AutoMapper-users
I believe that's mostly correct, but I don't know anything about ReverseMap. You may need to actually specify an opt.MapFrom(src => src.BestTimeToCall.Value); following the Condition().

Thanks

John

Reply all
Reply to author
Forward
0 new messages