I've set my mapping up as follows:
CreateMap<SourceClass, DestinationClass>().ForMember(destinationMember => destinationMember.Provider,
memberOptions => memberOptions.MapFrom(src => src.Providers.FirstOrDefault()));
Where I'm mapping from a List in my SourceClass to a string in my destination class.
My question is, how can I handle the case where "Providers" is null?
I've tried using:
src?.Providers?.FirstOrDefault()
but I get an error saying I can't use null propagators in a lambda.
I've been reading up on Automapper and am still unsure if AM automatically handles the null case or not. I tried to build the expression tree, but was not able to see any information that provided additional informations.
If it helps, I'm using automapper v 6.1.1.
src?.Providers?.FirstOrDefault() ?? "". This sets the value to an empty string if the expression proceeding??evaluates to null.