Can I configure AutoMapper to read from custom column names when mapping from IDataReader?

Posted by rohancragg on Stack Overflow See other posts from Stack Overflow or by rohancragg
Published on 2010-06-17T11:52:20Z Indexed on 2010/06/17 14:33 UTC
Read the original article Hit count: 245

Psuedo code for mapping configuration (as below) is not possible since the lambda only lets us access Type IDataReader, wheras when actually mapping, AutoMapper will reach into each "cell" of each IDataRecord while IDataReader.Read() == true:

var mappingConfig = Mapper.CreateMap<IDataReader, IEnumerable<MyDTO>>();
mappingConfig.ForMember(
    destination => destination.???,
    options => options.MapFrom(source => source.???));

Can anyone think of a way to do this using AutoMapper configuration at runtime or just some other dynamic approach that meets the requirement below.

The requirement is to support any incoming IDataReader which may have column names that don't match the property names of MyDTO and there is no naming convention I can rely on. Instead we'll ask the user at runtime to cross-reference the expected column names with the actual column names found in the IDataReader via IDataReader.GetSchemaTable().

© Stack Overflow or respective owner

Related posts about .NET

Related posts about automapper