views:

1500

answers:

4

I have worked on several distributed client/server projects recently, and one pain point that we always run into is translating the DTO objects into our entities and vice-versa. I was wondering if anyone has a "simple" solution to this time sink?

One thing I thought about was coming up with some sort of translation using reflection...I guess you'd have to make sure your property names were exactly the same on each side of the wire - but seems like it might work.

Just looking for a way to avoid some of this time sink in my development.

Thanks!!

+1  A: 

Pain and risk

of getting/setting properties by hand! Have you tried this: http://dozer.sourceforge.net/.

A flexible and configurable framework for translating bean to bean. Might help!

paulosuzart
A: 

I've had success using tools like XDoclet (although it shouldn't be to hard to script) to automatically generate transfer objects and simple entity translations.

That said, if you believe your Entity translations are simple enough to be done using reflection, is there a reason you can't just pass the Entity objects over the wire instead of DTO's? It might be better to have a slightly custom serialization than a full blown DTO.

cynicalman
+2  A: 

I have been using AutoMapper recently, and it works like a charm.

CitizenBane
A: 

use ValueInjecter, with it you can map anything to anything e.g.

 object <-> object
 object <-> Form/WebForm
 DataReader -> object

and it has cool features like: flattening and unflattening

the download contains lots of samples (sample applications for asp.net mvc, web-forms, winforms, unit tests)

Omu