0
我有抽象類AbsProduct
Automapper返回null
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
。