[英]Automapper returns null
I've the abstract class AbsProduct
我有抽象类
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
: 和
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
: 问题是当我尝试将
ProductDTO
映射到AbsProduct
:
var product = AutoMapper.Mapper.Map<ProductDTO, AbsProduct>(productDTO);
AutoMapper
is returning null
, but the source( productDTO ) isn't null
. AutoMapper
返回null
,但是source( productDTO )不为null
。
You can't instantiate an abstract
class. 您不能实例化一个
abstract
类。
Try create a type that derives from AbsProduct
and use that type instead of it. 尝试创建一个从
AbsProduct
派生的类型,并使用该类型代替它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.