Nikshep
Nikshep

Reputation: 2115

Best pattern to implement Translators between DB type object to Business type object

Our project had implemented Entity framework and we were floating the entity object type across all layers. Due to the sheer size of those objects we have decided to have business entities and data entities. Now I am confused as in 1) Where to implement the translation of these objects 2) How i.e any patterns or practices which I should follow to get better results.

*Edited * Thanks for all the replies I am looking into Automapper and found it might fit well. But instead of using a library I wanted to create my own translator which would seem like reinventing the wheel. But my thought is I would have a lot more control on things then.

So going back to the original quesiton

  1. On which layer should I implement my translation i.e we have an N-tire app and there are two schools of thought one being we should have a business layer and treat it as a facade and implement all translation and other business logic there and treat all others layer as a dumb layer which have no knowledge about the other layers and keep minimum reference of them so the data layer would be throwing out the same data entities and can be reused in another project where the Business object are somewhat different then our current object. The second school of thought is that the data layer should be returning and accepting business entities which would restrict non-database developers from unnecessary call on the db layer to create a business entitie.
  2. Any patterns which are there for such kind of translation libraries.

Upvotes: 2

Views: 1432

Answers (3)

Denis Biondic
Denis Biondic

Reputation: 8201

You can try DTO's and ValueInjecter if you are moving data over the wire, or the same tool if you use ViewModels to bind to Views ... AutoMapper is great too.

Upvotes: 0

keithwarren7
keithwarren7

Reputation: 14280

This sounds similar to the problem faced by many people when using the MVVM pattern in association with an ORM. Automapper (http://automapper.codeplex.com/) is a great library that provides clean, convention based translation between types.

Upvotes: 1

Jethro
Jethro

Reputation: 5916

Please take a look the following, it has a really nice overview of all of microsoft techs. It might be a bit complicated though but it shows the layers very nicely.

N Layer sample app

Upvotes: 0

Related Questions