Ignore mapping List if null

Skip to first unread message

Marius Fjeldet

Jan 3, 2022, 5:21:59 AMJan 3
to AutoMapper-users
I posted a question in StackOverflow a little over a week ago, which I think formats my example code better than in here:

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
0 new messages