Skip to content

Instantly share code, notes, and snippets.

@svallory
Created September 6, 2012 03:22
Show Gist options
  • Save svallory/3650672 to your computer and use it in GitHub Desktop.
Save svallory/3650672 to your computer and use it in GitHub Desktop.
AutoMapper Two-way mapping
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() })));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment