I have several non-nullable GUID properties in my Code First data model that map to Guid? in my view models. I have no use for the empty GUID (all zeroes), so I use the following mappings, but I can’t help wondering if there is a neater way of doing this? The uncharted depths of AutoMapper configuration would take me years to explore all on my own.
Mapper.CreateMap<Guid, Guid?>().ConvertUsing(guid => guid == Guid.Empty ? (Guid?)null : guid);
Mapper.CreateMap<Guid?, Guid>().ConvertUsing(guid => !guid.HasValue ? Guid.Empty : guid.Value);
Create a custom type converter.
https://github.com/AutoMapper/AutoMapper/wiki/Custom-type-converters
Then: