1

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?

Steve Brother
  • 838
  • 2
  • 11
  • 21

2 Answers2

0

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

mjwills
  • 23,389
  • 6
  • 40
  • 63
  • Okay, I see where you're going with this, but the documentation is scant. How do I implement this with my code above? Can you give example(s)? – Steve Brother Jul 10 '17 at 13:38
  • Is swapping to AutoMapper 3.1.1 an option? – mjwills Jul 10 '17 at 13:40
  • I could consider it yes; however, my team does like to keep up with the latest packages that are out there, and if there's a way to keep it current, it would me much appreciated. – Steve Brother Jul 10 '17 at 13:42
0

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());
Venu
  • 455
  • 2
  • 7