我有抽象类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);
}ProductDTO:
public class ProductDTO
{
public int ID { get; set; }
public int Price { get; set; }
public int Category { get; set; }
public string Name { get; set; }
}我的配置是
AutoMapper.Mapper.Initialize(config =>
{
config.CreateMap<AbsProduct, ProductDTO>();
config.CreateMap<ProductDTO, AbsProduct>();
});问题是当我试图将ProductDTO映射到AbsProduct时
var product = AutoMapper.Mapper.Map<ProductDTO, AbsProduct>(productDTO);AutoMapper正在返回null,但源(ProductDTO)不是null。
发布于 2017-04-02 11:07:44
不能实例化abstract类。
尝试创建一个从AbsProduct派生的类型,并使用该类型代替它。
https://stackoverflow.com/questions/43167557
复制相似问题