AutoMapper 版本 5 映射 IDataReader

AutoMapper version 5 mapping IDataReader

我正在尝试从 IDataReader 映射到 Person,但我总是得到 0 个结果: https://github.com/AutoMapper/AutoMapper/issues/874

简介:

internal class ImportAddressProfile : Profile
{
    private readonly IContainer _container;

    public ImportAddressProfile(IContainer container)
    {
        _container = container;

        CreateMap<IDataReader, Person>();
       CreateMap<IDataReader, List<Person>>();
    }
}

public class Person
{
    public string FirstName { get; set; }
    public int Amount { get; set; }
}

运行: ...

var dt = new DataTable();
dt.Columns.Add("FirstName", typeof(string));
dt.Columns.Add("Amount", typeof(int));
dt.Rows.Add("John", 123);
dt.Rows.Add("Bob", 2);

IDataReader reader = dt.CreateDataReader();
List<Person> People = Mapper.Map<IDataReader, List<Person>>(reader);

// returns zero results

我已经尝试添加 nuget 包:https://www.nuget.org/packages/automapper.data

AutoMapper.Data 在 AutoMapper 5 中不受支持。我将它分解到它自己的存储库中,主要是因为我不使用它并且对代码的作用一无所知。如果您有兴趣让它工作,我很乐意接受任何让它与 AutoMapper 5 一起工作的人的 PR。