2

I'm planning my first architecture that uses DTOs. I'm now exploring how to map the modified client-side domain objects back to the DTOs that were originally retrieved from the data service. I must map back to the original object graph, instead of instantiating a new one, in order to use WCF Data Services Client Library's change tracking feature.

To put it in general terms, I need a tool that maps instances and (recursively) their sub-instances (collectively called the "source graph") to existing instances and (recursively) sub-instances (collectively called the "target graph") in a manner that is (nearly) 100% convention, rather than configuration, based.

The specific required functionality that I can think of is:

  1. Replace single-valued properties within the target graph with their corresponding values from the source graph.
  2. Synchronize collection pairs: elements that were added to a collection within the source graph should then be added to the corresponding collection within the target graph; elements removed from a collection within the source graph should then be removed from the corresponding collection within the target graph.

When it comes to mapping DTOs, it seems many people use AutoMapper. So I had assumed this task would be easy using that tool. Upon looking at the details, though, I have doubts it will fit my requirements. This indicates AutoMapper won't handle #1 so well. Equally so, this indicates AutoMapper won't help much with #2 either.

I don't want to try bending AutoMapper to my purposes if it will lead to a lot of configuration code. That would defeat the purpose of using a convention-based tool in the first place. So I'm wondering: what's a better tool for the job?

Community
  • 1
  • 1
HappyNomad
  • 4,458
  • 4
  • 36
  • 55
  • this might be a good start for you http://valueinjecter.codeplex.com/wikipage?title=Faster%20Deep%20Cloning%20using%20SmartConventionInjection%20and%20FastMember&referringTitle=Home, it's deep clonning code, I know others have modified it to do what you're trying to do, so it should help you. This is the old version: http://valueinjecter.codeplex.com/wikipage?title=Deep%20Cloning, you can see in the comments ppl speaking about the same thing that you are doing – Omu Dec 02 '13 at 10:41
  • 1
    I would agree - AutoMapper was never, ever built for cloning/synchronization. It's about 1-way maps. Not 2-way/bidirectional. – Jimmy Bogard Dec 03 '13 at 14:03

0 Answers0