0

I've the abstract class AbsProduct

public abstract class AbsProduct
{
    [Key]
    public int ID { get; set; }
    public int Price { get; set; }
    public int Category { get; set; }
    public string Name { get; set; }

    public abstract double Accept(IProductVisitor visitor);

}

and the ProductDTO:

public class ProductDTO
{
    public int ID { get; set; }
    public int Price { get; set; }
    public int Category { get; set; }
    public string Name { get; set; }
}

My configuration is

AutoMapper.Mapper.Initialize(config =>
{
    config.CreateMap<AbsProduct, ProductDTO>();
    config.CreateMap<ProductDTO, AbsProduct>();
});

The problem is when I try to map ProductDTO to AbsProduct:

var product = AutoMapper.Mapper.Map<ProductDTO, AbsProduct>(productDTO);

AutoMapper is returning null, but the source(productDTO) isn't null.

1 Answer 1

1

You can't instantiate an abstract class.

Try create a type that derives from AbsProduct and use that type instead of it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.