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
Is it possible to merge two objects in a way that properties will be copied from source to destination only if in the source they are not NULL? Using JavaScript syntax for spread ... operator or Object.assign() method as an example.
I was able to achieve similar functionality with Automapper by checking, if the relevant property in the source is NULL, then do not override it in the destination.
varsetup=newMapperConfiguration(expression =>{expression.CreateMap<DemoModel,DemoModel>().ForAllMembers(o =>o.Condition((x,y,memberX,memberY)=>memberXis not null));};varmapper=setup.CreateMapper();varsource=newDemoModel{Name:"X"};vardestination=newDemoModel{Name:"Y",Items:new[]{1,2,3}};varres=mapper.Map(source,destination);// Expected result is { Name: "X", Items: new[] { 1, 2, 3 }} so only Name property got overridden
Unfortunately, Automapper implements some ridiculously horrible behavior by clearing collections even when they're not supposed to be touched.
Question
Is merging, aka overriding only specific properties, possible in mapper without breaking collections?
The text was updated successfully, but these errors were encountered:
Is it possible to merge two objects in a way that properties will be copied from source to destination only if in the source they are not NULL? Using JavaScript syntax for spread
...
operator orObject.assign()
method as an example.I was able to achieve similar functionality with Automapper by checking, if the relevant property in the
source
is NULL, then do not override it in the destination.Unfortunately, Automapper implements some ridiculously horrible behavior by clearing collections even when they're not supposed to be touched.
Question
Is merging, aka overriding only specific properties, possible in mapper without breaking collections?
The text was updated successfully, but these errors were encountered: