Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can automapper ignore destination if it is not null / only change null fields

Tags:

automapper

Background: I'm working on a webservice that I want to allow input that has a null field to mean, "don't do an update". The input object is very similar but not identical to the database model, so we're using automapper to do the transforms.

So in the case of an update, I'd like to be able to take the existing values, use them to override any of the null fields in the input, and then save that to do the whole update. So is there a way to make automapper only put values into the destination if the destination field is null?

like image 349
Seneca Avatar asked Nov 14 '22 04:11

Seneca


1 Answers

Yes, it can, but you probably wouldn't want to go through the hassle. To do this, you're going to need to have a custom map handler for every field on the object that you want to do this (You may be able to share the custom handler among properties of the same type, but I'm not 100% sure without looking at some of my old code).

like image 189
Charles Boyung Avatar answered Jun 26 '23 09:06

Charles Boyung