Ignore mapping List if null

834 views
Skip to first unread message

Marius Fjeldet

unread,
Jan 3, 2022, 5:21:59 AM1/3/22
to AutoMapper-users
Hi,
I posted a question in StackOverflow a little over a week ago, which I think formats my example code better than in here:
https://stackoverflow.com/questions/70453055/automapper-does-not-ignore-list-when-mapping-from-source-to-existing-destination

Is there a generic way to make AutoMapper ignore Lists when mapping to an existing object? By setting the config  AllowNullCollections to true, I am able to maintain the null value when creating a new object, but when mapping a null-List to an existing object, the existing object will have it's List replaced with an empty list.

The answer I got on StackOverflow seems to work when I specify the List property manually, but I would like a generic option to not have to remember this. 

Hope it's OK to ask here, as I have not yet gotten any response in SO :) 

Reply all
Reply to author
Forward
0 new messages