Created
January 3, 2012 15:18
-
-
Save jingalls/1555307 to your computer and use it in GitHub Desktop.
Automapper Map with Anonymous function not working in version 2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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