Created
June 20, 2017 16:18
-
-
Save lbargaoanu/908eb76ad493ee176a6b7a45d903ef8d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
static void Main() | |
{ | |
Mapper.Initialize(cfg => | |
{ | |
//cfg.AllowNullDestinationValues.Dump(); | |
cfg.CreateMap<TimesheetModel, TimesheetViewModel>() | |
.ForMember(d=>d.Contact, o=>o.MapFrom(s=>s.ContactNavigation.Id)) | |
.ReverseMap(); | |
}); | |
Mapper.AssertConfigurationIsValid(); | |
try{ | |
Mapper.Map<TimesheetModel>(new TimesheetViewModel()).Dump(); | |
}catch(Exception ex){ | |
ex.ToString().Dump(); | |
} | |
} | |
public partial class TimesheetModel | |
{ | |
public int ID { get; set; } | |
public DateTime? StartDate { get; set; } | |
public int? Contact { get; set; } | |
public ContactModel ContactNavigation { get; set; } | |
} | |
public class TimesheetViewModel | |
{ | |
public int? Contact { get; set; } | |
public DateTime? StartDate { get; set; } | |
} | |
public class ContactModel | |
{ | |
public int Id { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment