Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to map null values with AutoMapper for an specific mapping?

I found this solution AutoMapper - setting destination string to null actually makes it string.Empty

but It uses the Initialize method so all the mappings behavior would change along the app : O

And I just need do it for a specific mapping.

like image 530
SDReyes Avatar asked Feb 03 '10 16:02

SDReyes


1 Answers

Found a solution:

Mapper.Initialize( Conf =>
  {
    Conf.ForSourceType<MyGreatViewModel>().AllowNullDestinationValues = true;
  } );

Thanks guys : )

Take care of your destination field types (remember you need nullable types. e.g. 'Byte?' )

like image 183
SDReyes Avatar answered Oct 19 '22 04:10

SDReyes