Skip to content

Instantly share code, notes, and snippets.

@jingalls
Created January 3, 2012 15:18
Show Gist options
  • Save jingalls/1555307 to your computer and use it in GitHub Desktop.
Save jingalls/1555307 to your computer and use it in GitHub Desktop.
Automapper Map with Anonymous function not working in version 2.0
using System.Linq;
using AutoMapper;
public static class AutoMapperConfig
{
public static void CreateMappings()
{
Mapper.CreateMap<User, ConfigurationUserViewModel>()
.ForMember(dest => dest.Email, opt => opt.MapFrom(src =>
{
var email = src.ContactMechanisms.SingleOrDefault(cm => cm.ContactMechanismTypeId == ContactMechanismType.EMAIL && cm.IsPreferred == true);
return email == null ? string.Empty : email.Data;
}));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment