Automapper DynamicMap missing

2019-08-25 01:57发布

问题:

I was reading in a previous question on "How to use AutoMapper to map a DataRow to an object in a WCF service?" and I thought 'Great! That's what I'm looking for on mapping a table from MySQL!', yet after I got the Nuget package and tried to use that line of code like this:

List<Customer> c = AutoMapper.Mapper.DynamicMap<IDataReader, List<Customer>>(dt.CreateDataReader());

I got this exception:

'Mapper' does not contain a definition for 'DynamicMap'

After checking around on the 'net about it, I found out it's been taken out. So then how does one create a List from MySQL DB Table?

回答1:

DataReaderMapper can be used to achieve this. See https://github.com/aygjiay/AutoMapper.DataReaderMapper or https://github.com/AutoMapper/AutoMapper.Data for details.



回答2:

The AutoMapper has many changes since the 3.1.1 version.

The below change from DynamicMap method to Map method should work.

List<Customer> c = AutoMapper.Mapper.Map<IDataReader, List<Customer>>(dt.CreateDataReader());


标签: c# AutoMapper