pdiddy
pdiddy

Reputation: 6297

EF POCO DTO WCF Adapter pattern

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?

Upvotes: 2

Views: 1881

Answers (2)

Arron S
Arron S

Reputation: 5537

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.

Upvotes: 1

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364409

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.

Upvotes: 3

Related Questions