I tried creating a mapping to a string using the following CreateMap()
:
Mapper.CreateMap<MyComplexType, string>()
.ConvertUsing(c => c.Name);
But when I try to use this mapping, I get the following error:
Type 'System.String' does not have a default constructor
That makes sense, but I've been reading around and supposedly this should work. Is there something else I have to do?
In my case I was using
To project directly from a DBContext collection (EF 6) to my DTO e.g.
With a destination with an
IEnumerable<string>
property coming from a M-M related table i.e.and my solution was mapping as follows
N.B. I am using the ProjectTo<> like this to avoid the common lazy loading select n+1 problem and ensure decent (quick) sql runs against the DB, and I have all the related table data I need. Excellent.
Thanks Jimmy Bogard you rockstar !!!