public
Last active

AutoMapper Two-way mapping

  • Download Gist
gistfile1.cs
C#
1 2 3 4 5 6
Mapper.CreateMap<Design, DesignSubmitViewModel>()
.ForMember(d => d.Tags, opt => opt.MapFrom(d => d.Tags.Aggregate("", (total, tag) => total + (tag.Name + ", ")).Trim(' ',',')));
 
Mapper.CreateMap<DesignSubmitViewModel, Design>()
.ForMember(d => d.Competition, opt => opt.Ignore())
.ForMember(d => d.Tags, opt => opt.MapFrom(d => d.Tags.Split(',').Select(name => new Tag() { Name = name.Trim() })));

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.