public static void Main()
var foo = new MyModel { Id = 1, Name = "Foo", Unmapped = "Unmapped" };
var dto = MyMapper.GetMapper().Map<MyViewModel>(foo);
dto = new MyViewModel { Id = 2, Name = "DTO" };
var newDto = MyMapper.GetMapper().Map<MyViewModel, MyModel>(dto, foo);
foo = MyMapper.GetMapper().Map<MyViewModel, MyModel>(dto);
public static class MyMapper
public static IMapper GetMapper()
var mapperConfig = new MapperConfiguration(
configuration.CreateMap<MyViewModel, MyModel>()
.IgnoreAllPropertiesWithAnInaccessibleSetter()
.ForPath(s => s.Unmapped, opt => opt.Ignore())
.ForPath(s => s.Id, opt => opt.Ignore())
mapperConfig.AssertConfigurationIsValid();
return mapperConfig.CreateMapper();
public int Id { get; set; }
public string Name { get; set; }
public string Unmapped { get; set; }
public int Id { get; set; }
public string Name { get; set; }