I swear I've done it before, but I can't seem to get it to work now. Basically I'm getting an EndUser
containing a Site
, and I want to map that Site
to a SiteInfo
object.
Here's my map configuration:
Mapper.CreateMap<Site, SiteInfo>()
.ForMember(dest => dest.SiteID, opt => opt.MapFrom( src => src.ID))
.ForMember(dest => dest.CompanyID, opt => opt.MapFrom(src => src.Company.ID));
Mapper.CreateMap<EndUser, SiteInfo>()
.ForMember( dest => dest, opt => opt.MapFrom(src => src.Site ));
So EndUser.Site
should be able to map to SiteInfo
. I can do this on the outside by just calling Mapper.Map<SiteInfo>(EndUser.Site)
. I think it's just cleaner syntax to map from the end user to the location info directly.
So how can I map directly from EndUser
to SiteInfo
? Basically this is the code I'd LIKE to write:
var user = mcp.Users.GetEndUser(userAddress.Address);
var siteInfo = Mapper.Map<SiteInfo>(user);
Currently I'm working around the issue by just mapping from EndUser.Site
like this:
var user = GetEndUser(emailAddress);
var siteInfo = user == null
? null as SiteInfo
: Mapper.Map<SiteInfo>(user.Site);