0
votes

I have a WCF service layer which uses pure DTOs.

On the server side, I take these DTOs and pass them to my business logic layer, basically a set of "Manager" classes for each entity or group of entities.

The Manager class methods take in a DTO as a paramater, in the first lines of each method, I take the DTO and using AutoMapper, map it to my Entity Framework POCO. Then I do my LinQ queries or repository methods (I'm using DBContext from EF 4.1), and if needed, map the result entity back to a DTO and return it back to WCF service method.

Almost every method in my Manager class is doing this mapping and remapping, it's a ton of repetative boilerplate code. Any suggestions on a pattern I can use to reduce redundancy?

3
Please provide some code sampleshazzik

3 Answers

0
votes

You don't need pattern - you just need to wrap that repetitive code in helper method and reuse that method.

0
votes

If you want to use Entity Framework in WCF architecture. i think the best choice is POCO Self-Tracking Entities, it is provided as a Visual Studio Item Template, which can be created from the Designer.

MSDN : Working with Self-Tracking Entities

0
votes

We place all mappings in a separate dll. It makes it easier to test, and removes the need for duplicate code.

You can also reduce the amount of code further by using automapper, see: http://automapper.codeplex.com/