misuk
misuk

Reputation: 225

complex mapping with automapper

I have a complex object (returned from a web service api). It has multiple nested items, some of which contain lists of property names & values (key value pairs). for example

a meterdetail class can contain multiple meter objects, each meter object has multiple rows, each row has a key (the property name) and a value (the propertyvalue). I need to map each row to a specific property of a class, so

  1. row 1 key 'core' value maps to the 'Core' property of my meter class
  2. row 2 key 'serial_number' value maps to the SerialNumber property of my meter class
  3. row 3 key 'install_date' value maps to the InstallDate property of my meter class

and so on

is this possible with automapper ? If so, how would I do this ? Im using .netcore 5 and C# Id greatly appreciate some advice

Upvotes: 0

Views: 471

Answers (1)

Neil Barnwell
Neil Barnwell

Reputation: 42105

I wouldn't bother. AutoMapper's great for simple 1-1 mappings from one type to another where they look basically the same, but if you did manage to do what you're asking with AutoMapper, you'd just be hiding complex logic in a mapping class away from where things are happening. If it were me, I'd spend the time literally just doing it by hand, instead. You'll thank yourself for it later, I imagine.

Upvotes: 1

Related Questions