Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

What is the best approach to mapping between Entity, View Model or dataContract.

For example I've seen the following modelling structures for SOA.

WCF -> DataContract distributed to client.

Middle-tier -> Models and Interface with then mapped to repository type and eventual a concrete class which implements a ORM.

In some cases I've seen reflection used, others just setting the properties and third-party libraries like AutoMapper for C#.

What is the most effective way to keep your system "easy to maintain" and functional or horses for courses?

EDIT: Question wasn't focused on Microsoft, I've used SOA for java and the same problem happens regarding mapping. I'm asking about direct mapping vs. reflection and etc? Its really got nothing to do with ORMs.

e.g.

    thesolution.models.interfaces
    public interface IProduct { //bundle of properties and method signatures }

    thesolution.models
    public abstract class Product  implements IProduct { //implementation }

    thesolution.repositories.sapMD
    public class Product extends Product implments IProduct { //implements and do stuff}

    thesolution.repositories.sapCRM
    public class Product extends Product implments IProduct { //implements and do stuff}

    thesolution.controllers  
    public class ProductController 
    {
      public IActionResponse Save(IProduct product)
      {
          //save to sapMD repository
          IAction actionMd = ((thesolution.repositories.sapMD.Product)product).Save();

           //save to sapCRM repository
          IAction actionCrm = ((thesolution.repositories.sapMD.Product)product).Save();

          IActionResponse response = new thesolution.message.product.ActionResponse(); 
          response.Actions.Add(actionMd);
          response.Actions.Add(actionCrm);
          return response;
      } 

    }

      thesolution.DataContracts
      //XSD JAXB or etc.


thesolution.Services

//your service method

public class ProductServices ... {

  public thesolution.DataContracts.ResponseAction Save(thesolution.DataContracts.Product product){

    // so now how do you map back to IProduct manually, reflection or etc.

}

}
share|improve this question
2  
You might want to accept answers to your questions as a way to encourage folks to participate. –  S.Lott Jul 14 '11 at 9:55

2 Answers 2

up vote 2 down vote accepted

Personally I've had success with Domain Driven Design (DDD). DDD is not suitable for everyone.

However I suspect if you're using Service Oriented Architecture (SOA) then you may have suitably complex business logic to abstract away so that it can be changed independently of your architecture.

DDD and SOA have a kind of symbiosis. I don't have any direct resources to link, however Udi Dahan does training courses regarding using DDD & SOA.

Update: Heres a video of Udi Dahan giving a talk about using DDD with SOA.

share|improve this answer

Take the hint.

If it was easy, Microsoft would not have invented so many choices. If you Google "Entity Framework", you'll find even more (POCO EF4, etc.)

You can read articles like this: http://blogs.msdn.com/b/esql/archive/2007/12/14/entityframework_5f00_orm.aspx

Sadly, it's hard because -- possibly -- Microsoft has a lot of internal politics. All of their products need a place in the architecture, so there's a lot of mappings among all the various pieces and parts. It's hard for Microsoft to simplify anything. (Oracle may have the same kind of problem.)

If you step away from the Microsoft World View, however, it's still difficult, but it may not be quite so complex. Fewer products means fewer mappings.

Many folks use Object-Oriented databases (with no mappings) or very simple ORM tools (with very simple mappings in exactly one place.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.