I met today with strange behavior of AutoMapper library. Why string.Format in the second case does not work? Are you able to explain to me why the first case works when the second throwing an exception?
Mapping configuration: (working)
config.CreateMap<Person, PersonView>().
ForMember(dest => dest.FullName, opt => opt.
MapFrom(src => src.Data.Code + " - " + src.Number));
Mapping configuration: (not working)
config.CreateMap<Person, PersonView>().
ForMember(dest => dest.FullName, opt => opt.
MapFrom(src => string.Format("{0} - {1}", src.Data.Code, src.Number)));
Projection:
using (var ctx = new MyDbContext())
{
return ctx.Persons.Include(i => i.Data).Project().To<PersonView>().ToList();
}
Exception: