Reputation: 307
I want to convert one List to another using AutoMapper, but it returns an empty list
This is my source object
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; }
}
This is my destination object
public class ChargeVM
{
public int ChargeID { get; set; }
public string ChargeName { get; set; }
public bool IsActive { get; set; }
}
This is my AutoMapper mapping
List<Charge> chargeList= GetActiveChargeTemplates();
Mapper.CreateMap<List<Charge>, List<ChargeVM>>();
List<ChargeVM> list=Mapper.Map<List<Charge>, List<ChargeVM>>(chargeList);
this return list as an empty list with count=0.
Am I doing something wrong here?
Upvotes: 3
Views: 3940
Reputation: 789
Change
Mapper.CreateMap<List<Charge>, List<ChargeVM>>();
to
Mapper.CreateMap<Charge, ChargeVM>();
You don't have to explicitly create maps for list, only the objects in the list.
Upvotes: 8