我有这段代码:
Mapper.AddMap<Product, DetailsVM>(src =>
{
var res = new DetailsVM();
res.InjectFrom(src); // maps properties with same name and type
res.test = "asd";
return res;
});
productVM.InjectFrom(test);
我有一切正常,这是我的VM:
public int ProductId { get; set; }
public decimal Cost { get; set; }
public decimal UnitPrice { get; set; }
public int OnHandQty { get; set; }
public ProductPicture thumb { get; set; }
public ProductPicture main { get; set; }
public string test { get; set; }
实际模型没有属性test
,我只想将test
设置为任何字符串。我该怎么做?每当我尝试映射时,我都会继续null
。
答案 0 :(得分:1)
您需要拨打Mapper.Map
而不是InjectFrom
,
InjectFrom
不受Mapper.AddMap