I'm trying to map two entities - ProductPictureDTO with ProductPictureBDO - using the Automapper, but I get an exception and I'm not able to understand what is thew mistake.
The error
Missing type map configuration or unsupported mapping.
Mapping types: ProductPictureDTO -> Guid ERP.DTO.Products.ProductPictureDTO -> System.Guid
Destination path: ProductPictureBDO
Source value: ERP.DTO.Products.ProductPictureDTO
Here below you can see ProductPictureDTO
[DataContract]
public class ProductPictureDTO
{
[DataMember]
public Guid ProductPictureId { get; private set; }
[DataMember]
public byte[] Image { get; set; }
[DataMember]
public Guid ProductId { get; set; }
[DataMember]
public virtual ProductDTO Product { get; set; }
}
Here below the properties of ProductPictureBDO
public class ProductPictureBDO : IEntity<ProductPictureBDO>, IValidation
{
public const string PICTURE_CONTENT_NOT_VALID_ERROR_MESSAGE = "Picture: the content of the picture is not valid";
public const string ASSOCIATED_PRODUCT_NOT_VALID_ERROR_MESSAGE = "Picture: the picture is not associated to a product";
public ProductPictureBDO(Guid id)
{
ProductPictureId = id;
}
public Guid ProductPictureId { get; private set; }
public byte[] Image { get; set; }
public bool Deleted { get; private set; }
#region Navigation properties
public virtual ProductBDO Product { get; set; }
public Guid ProductId { get; set; }
}
Here below the method which tries to map the two entities
public IEnumerable<IError> ValidateProductPicture(ProductPictureDTO picture)
{
return _productsManager.ValidateProductPicture(ProductsMapper.Convert<ProductPictureDTO, ProductPictureBDO>(picture));
}
Here below the class responsible for mapping
public static class ProductsMapper
{
static ProductsMapper()
{
MapProductBDOToDTO();
MapProductDTOToBDO();
MapProductCategoryBDOToDTO();
MapProductCategoryDTOToBDO();
MapIvaBDOToDTO();
MapIvaDTOToBDO();
MapProductSupplierBDOToDTO();
MapProductSupplierDTOToBDO();
MapProductPictureBDOToDTO();
MapProductPictureDTOToBDO();
MapProductNoteBDOToDTO();
MapProductNoteDTOToBDO();
MapStockProductBDOToDTO();
MapStockProductDTOToBDO();
MapTagBDOToDTO();
MapTagDTOToBDO();
}
public static TTargetType Convert<TToConvert, TTargetType>(TToConvert toConvert)
{
return Mapper.Map<TTargetType>(toConvert);
}
private static void MapProductDTOToBDO()
{
Mapper.CreateMap<ProductDTO, ProductBDO>();
}
private static void MapProductBDOToDTO()
{
Mapper.CreateMap<ProductDTO, ProductBDO>().ReverseMap();
}
private static void MapProductCategoryDTOToBDO()
{
Mapper.CreateMap<ProductCategoryDTO, ProductCategoryBDO>();
}
private static void MapProductCategoryBDOToDTO()
{
Mapper.CreateMap<ProductCategoryBDO, ProductCategoryDTO>();
}
private static void MapIvaDTOToBDO()
{
Mapper.CreateMap<IvaDTO, IvaBDO>();
}
private static void MapIvaBDOToDTO()
{
Mapper.CreateMap<IvaBDO, IvaDTO>();
}
private static void MapProductSupplierDTOToBDO()
{
Mapper.CreateMap<ProductSupplierDTO, ProductSupplierBDO>();
}
private static void MapProductSupplierBDOToDTO()
{
Mapper.CreateMap<ProductSupplierDTO, ProductSupplierBDO>().ReverseMap();
}
private static void MapProductPictureDTOToBDO()
{
Mapper.CreateMap<ProductPictureDTO, ProductPictureBDO>();
}
private static void MapProductPictureBDOToDTO()
{
Mapper.CreateMap<ProductPictureDTO, ProductPictureBDO>().ReverseMap();
}
private static void MapProductNoteDTOToBDO()
{
Mapper.CreateMap<ProductNoteDTO, ProductNoteBDO>();
}
private static void MapProductNoteBDOToDTO()
{
Mapper.CreateMap<ProductNoteDTO, ProductNoteBDO>().ReverseMap();
}
private static void MapStockProductDTOToBDO()
{
Mapper.CreateMap<StockProductDTO, StockProductBDO>();
}
private static void MapStockProductBDOToDTO()
{
Mapper.CreateMap<StockProductDTO, StockProductBDO>().ReverseMap();
}
private static void MapTagDTOToBDO()
{
Mapper.CreateMap<TagDTO, TagBDO>();
}
private static void MapTagBDOToDTO()
{
Mapper.CreateMap<TagDTO, TagBDO>().ReverseMap();
}
}
I get the exception in the method Convert of the class ProductMapper