I am using AutoMapper 6.0.2 in a .NET EF project and I can't seem to get AutoMapper to work.
In a tutorial that was using AutoMapper 4.x.x this was used:
class A
{
string Id;
string Name;
B test {get; set;}
}
class B
{
string Id;
string Name;
C test{ get; set;}
}
class C
{
string Name;
}
Mapper.CreateMap<C, CDto>();
Mapper.CreateMap<B, BDto>();
Mapper.CreateMap<A, ADto>();
return entities.Select(Mapper.Map<A, ADto>);
I have tried below but I always get exceptions later when I use Mapper.Map.
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<C, CDto>();
cfg.CreateMap<B, BDto>();
cfg.CreateMap<A, ADto>();
});
and
Mapper.Initialize(cfg =>
{
cfg.CreateMap<C, CDto>();
cfg.CreateMap<B, BDto>();
cfg.CreateMap<A, ADto>();
});