I am using Automapper with NPoco in my Web Api project. Here is my Dto's and models:
[TableName("Component")]
public class ComponentDto
{
[Column("Id")]
public int Id { get; set; }
public string BotanicalName { get; set; }
}
[TableName("FormulaComponent")]
public class FormulaComponentDto
{
[Column("Id")]
public int Id { get; set; }
[Reference(ReferenceType.Foreign, ColumnName = "ComponentId", ReferenceMemberName = "Id")]
public ComponentDto Component { get; set; }
}
public class Component
{
public int Id { get; set; }
public string BotanicalName { get; set; }
}
public class FormulaComponent
{
public int Id { get; set; }
public Component Component { get; set; }
}
I am trying to map one model to another using Automapper. Here is my automapper profile:
public class AutoMapperProfile : Profile
{
protected override void Configure()
{
//From Model to Dto
Mapper.CreateMap<FormulaComponent, FormulaComponentDto>().ReverseMap();
Mapper.CreateMap<ComponentDto, Component>().ReverseMap();
}
}
But when I'm trying, I have an exeption: "Missing type map configuration or unsupported mapping" :
public IEnumerable<FormulaComponent> GetAll()
{
var formulaComponents = _repository.Get().Include(x => x.Component).ToList();
return _mapper.Map<IEnumerable<FormulaComponentDto>, IEnumerable<FormulaComponent>>(formulaComponents);
}
UPD: automapper initialized into LightInject:
public partial class Startup
{
public static void InitLightInject(HttpConfiguration config)
{
var container = new ServiceContainer();
Mapper.AddProfile<AutoMapperProfile>();
container.Register<IMappingEngine>(c => Mapper.Engine);
}
}