Mapping of BE to DC is a lot of work

Topics: General Discussion Forum, July and December Releases Forum
Aug 15, 2007 at 11:48 AM
Can you please explain the reasoning for having to re-create all the members for a DataContract from scratch, instead of deducting them automatically from a Business Entity, or even using the BE as a data transfer object right thru to the service layer, and just decorate the BE class with the DataContract attributes? It seems like an awfull lot of work, or am I missing the point completely?
Aug 16, 2007 at 9:57 AM
Edited Aug 16, 2007 at 10:02 AM
Hello, I'm not an expert but I work with this pattern from 1 month and I think that it's interresting to create new objects because in business layer your objects contains relationships to other and you know which objects are loaded in memory or not.

But in a webservice the clients receiving objects must not test each relationship to see if it's null, thus you create objects without relationship, each object contains key of other if it's necessary.

In one case you 'll return an object with all the relationships and in an other case not.
In the first case you 'll return the parent object for example id 1, and a collection of the child objects (relationship) containing the parent id 1. You create the correct response message object containing the good objects (one object + a collection).
The next time you can only return the parent, or only a chil object, all cases are possible.

I think that you don't load all objects that have relationship (it's lazy loading like nhibernate).