0
votes

i want to map my datatable to List using automapper. i tried with below code but its not working, I'm getting below error.

var data = GetDataTableResult();
var result = Mapper.Map<IDataReader, IList<RollCall>(data.CreateDataReader()); 

public class RollCall
{
    public long Id { get; set; }
    public string CreationUserId { get; set; }
    public DateTime CreationTs { get; set; }
    public string LastChangeUserId { get; set; }
    public DateTime LastChangeTs { get; set; }
    public byte StatusType { get; set; }
    public DateTime EntryTs { get; set; }
    public int ClientId { get; set; }
    public int RollcallId { get; set; }
    public int VehicleId { get; set; }
    public double Quantity { get; set; }
    public double OpeningOdo { get; set; }
    public double ClosingOdo { get; set; }
    public int OrderId { get; set; }
}

Missing type map configuration or unsupported mapping. Mapping types: IDataReader -> IList1 System.Data.IDataReader -> System.Collections.Generic.IList1[[SampleDemo.RollCall, SampleDemo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] Destination path: IList`1 Source value: System.Data.DataTableReader

1

1 Answers

0
votes

Firstly Reset mapper and Creat Map then do mapper and change IList to List:

AutoMapper.Mapper.Reset();
AutoMapper.Mapper.CreateMap<IDataReader, RollCall>();
result = AutoMapper.Mapper.Map<IDataReader, List<RollCall>>(data.CreateDataReader());