I'm new to AutoMapper and have couple of questions regarding datatable to object mapping.I did some work but seems like something went wrong.
Mapper.CreateMap<IDataReader, OrderDest>().ConvertUsing<OrderDestTypeConverter>();
public class OrderDestTypeConverter : ITypeConverter<IDataReader, OrderDest>
{
public OrderDest Convert(ResolutionContext context)
{
var dest = new OrderDest();
if (!context.IsSourceValueNull && context.SourceValue is IDataReader)
{
var dr = (IDataReader) context.SourceValue;
dest.OrderQuantityDest = (int) dr["quantity"];
}
return dest;
}
}
In my repository class - I'm doing this
var crs = new CustomerRespositorySimulator();
DataTable orderlistsource = crs.GetCustomerOrders(12345);
var orderlistdest = Mapper.Map<IDataReader, List<OrderDest>>(orderlistsource.CreateDataReader());
For some reason the mapping does not work . I even attached a break in custom type converter OrderDestTypeConverter class and it never gets hit.
I'm doing any wrong in using customtype converter?.
Appreciate your help!.