It seems no, he will not take care of this automatically for you. Interestingly, it will map enum to a regular int .
Looking at the source of AutoMapper, I think the problematic line is :
Convert.ChangeType(context.SourceValue, context.DestinationType, null);
Assuming context.SourceValue = DummyTypes.Foo and context.DestinationType is int? , You'll get:
Convert.ChangeType(DummyTypes.Foo, typeof(int?), null)
which raises a similar exception:
Invalid listing from 'UserQuery + DummyTypes' for' System.Nullable`1 [[System.Int32, mscorlib, Version = 4.0.0.0
So, I think, really the question is, why can't we use a variable like enum to int? This question has already been asked here .
This seems like a bug in AutoMapper. In either case, the workaround is to manually display the property:
Mapper.CreateMap<DummySource, DummyDestination>() .ForMember(dest => dest.Dummy, opt => opt.MapFrom(src => (int?)src.Dummy));
Andrew Whitaker
source share