【发布时间】:2016-10-05 23:23:49
【问题描述】:
我想使用 AutoMapper 将一个列表转换为另一个列表,但它返回一个空列表
这是我的源对象
public class Charge
{
public int ChargeID { get; set; }
public string ChargeName { get; set; }
public int CreatedBy { get; set; }
public DateTime CreatedDate { get; set; }
public int ModifiedBy { get; set; }
public DateTime ModifiedDate { get; set; }
}
这是我的目标对象
public class ChargeVM
{
public int ChargeID { get; set; }
public string ChargeName { get; set; }
public bool IsActive { get; set; }
}
这是我的 AutoMapper 映射
List<Charge> chargeList= GetActiveChargeTemplates();
Mapper.CreateMap<List<Charge>, List<ChargeVM>>();
List<ChargeVM> list=Mapper.Map<List<Charge>, List<ChargeVM>>(chargeList);
此返回列表为 count=0 的空列表。
我在这里做错了吗?
【问题讨论】:
标签: c# automapper