我有一个像这样的源类:
public class Basket {}
像这样的目标类:
public class BasketModel
{
public string Property { get; set; }
}
和这样的映射:
Mapper.CreateMap<Basket, BasketModel>()
.ForMember(x => x.Property, o => o.ResolveUsing(x => "anything"));
现在我将原始模型中的“Property”属性设为虚拟,并创建了一个从模型继承的新类:
public class BasketModel
{
public virtual string Property { get; set; }
}
public class BasketModel2 : BasketModel
{
public override string Property
{
get
{
return "some value";
}
}
}
我已经更新了映射:
Mapper.CreateMap<Basket, BasketModel>()
.ForMember(x => x.Property, o => o.ResolveUsing(x => "anything"))
.Include<Basket, BasketModel2>();
并创建了映射
Mapper.CreateMap<Basket, BasketModel2>()
.ForMember(x => x.Property, o => o.Ignore());
现在,当我尝试映射到 BasketModel2 时,null
Property 的值不是 ,而是"anything"
。
我在这里想念什么?