Skip to content

Instantly share code, notes, and snippets.

@lbargaoanu
Created June 20, 2017 16:18
Show Gist options
  • Save lbargaoanu/908eb76ad493ee176a6b7a45d903ef8d to your computer and use it in GitHub Desktop.
Save lbargaoanu/908eb76ad493ee176a6b7a45d903ef8d to your computer and use it in GitHub Desktop.
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