This might be a stupid question! (n00b to AutoMapper and time-short!)
I want to use AutoMapper to map from EF4 entities to ViewModel classes.
1) If I call
<
CreateMap().ReverseMap()
.Member
(Property,Field,GetMethod()), you needn't call CreateMap
. Actually, if every member
in TDest
are all exist in TSrc
, you needn't call CreateMap
. The following code works.class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
class Person2
{
public string Name { get; set; }
public int? Age { get; set; }
public DateTime BirthTime { get; set; }
}
public class NormalProfile : Profile
{
public NormalProfile()
{
//CreateMap();//
}
}
var cfg = new MapperConfiguration(c =>
{
c.AddProfile();
});
//cfg.AssertConfigurationIsValid();
var mapper = cfg.CreateMapper();
var s3 = mapper.Map(new Person2 { Name = "Person2" });