You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am not able to find any config which could help with my problem. I want to update object but i don't want to update target fields with null fields from source. I want to ignore source fields if they are null.
The text was updated successfully, but these errors were encountered:
There's no quick way to achieve this, but it seems like a sensible thing to support, so I'll add it in. It's not going to be quick to add though, but thanks for the suggestion!
This is supported as of v1.5, which is now on NuGet. Sources can be ignored like this:
Mapper.WhenMapping.Over<Order>()// Apply the filter to Order updates.IgnoreSources(c =>c.If<string>(s =>s==null));// Ignore null source strings
Mapper.WhenMapping.From<OrderDto>()// Apply when mapping from OrderDto.Over<Order>()// Apply the ignore to Order updates (optional).IgnoreSource(dto =>dto.Id);// Ignore the Order.Id property
...or like this:
// Source, target and mapping types are implicit from the mapping:Mapper.Map(orderDto).Over(order, cfg =>cfg.If((dto,o)=>dto.Id==0)// Apply the ignores if OrderDto.Id is 0.IgnoreSource(
dto =>dto.Id,// Ignore Order.Id...
dto =>dto.OrderNumber);// ...and Order.OrderNumber
I am not able to find any config which could help with my problem. I want to update object but i don't want to update target fields with null fields from source. I want to ignore source fields if they are null.
The text was updated successfully, but these errors were encountered: