2

So I'm starting to look into using the EF with POCO and transfering DTO over the wire to client of my WCF.

Looks like it's a good architectural design to go with DTO instead of sending POCO over to the client.

So I was reading about it and a lot of time it mentionned using the Adapter pattern to convert the POCO to DTO.

I can't seem to find any article describing the Adapter patter used for POCO => DTO.

Can someone shed a bit of light concerning this?

Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
pdiddy
  • 6,217
  • 10
  • 50
  • 111

2 Answers2

3

Adapter is GoW pattern with exact meaning. You don't need special article to read about using it on top of POCO and DTOs (it is same like with any other classes). But I think you actually don't want a real adapter. You want something which will convert POCO to DTO and vice versa. Many developers are using very good library called AutoMapper. I usually don't use neither adapter or AutoMapper. Instead my DTO's have static methods called ToPoco and FromPoco - it is stupid, it is more writting but everybody understand it.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • I was wondering how to use it with the adapter pattern. Going with this http://www.dofactory.com/Patterns/PatternAdapter.aspx i was thinking so the target is the DTO ... so i create an adapter to wrap my poco? ... – pdiddy Feb 11 '11 at 01:22
1

This post talks about the purity of the two.

But as far as converting them from one to the other, I have used extension methods in the past.

So before the POCO is being sent over the wire, I have something like this.

accountPoco.toDTO()

which converts it into a WCF datacontract obj, serialized and sent across the wire.

On the other side I have

accountDto.toPOCO()

Which converts it back into POCO.

It's not the most elegant, but it works.

Community
  • 1
  • 1
Arron S
  • 5,511
  • 7
  • 50
  • 57