I can\'t get my head round the following issue. I have a feeling it is a limitation of LINQ and expression trees, but not sure how to accept the lambda body. Can I achieve this
In order to use lambda bodies, use .ResolveUsing
instead of .MapFrom
.
As per the author:
MapFrom has some extra stuff that needs expression trees (like null checking etc).
So your statement would look like this:
Mapper.CreateMap()
.ForMember(x => x.DateCreated, opt => opt.ResolveUsing(src => {
var dt = (DateTime)src.DateCreated;
return dt.ToShortDateString();
}));