0

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?

EkoostikMartin
  • 6,831
  • 2
  • 33
  • 62

3 Answers3

0

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

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
0

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/

Alberto L. Bonfiglio
  • 1,767
  • 23
  • 38
Shiraz Bhaiji
  • 64,065
  • 34
  • 143
  • 252
0

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

Ethan Wu
  • 428
  • 5
  • 15