WCF and Parent/Child Relationship

WCF and Parent/Child Relationship

Old forum URL: forums.lhotka.net/forums/t/9618.aspx


JasonG posted on Friday, October 08, 2010

Hello, I'm building a WCF service app using CSLA business objects. The business objects function correctly when tested by themselves. Where I'm stuck is in the service implementation. What is best way to transfer the child object to/from the datacontract. I looked at the Project Tracker app, but i don't see where the "Resources" child objects are converted into Datacontracts and back to child objects.

Can someone point me in the right direction?

thanks,

Jason

 

 

 

RockfordLhotka replied on Friday, October 08, 2010

Most service implementations are really just simple mapping functions.

Your business object graph has a shape (parent-child-grandchild, etc).

Your data contract has a shape too. So it is typically just a matter of doing a bunch of looping (or LINQ queries) to populate the data contract with business data, of course honoring any authorization rules in the process.

And it is that last part where the service code gets interesting, because you need to decide how to handle cases where the caller isn't authorized to see specific objects or property values. The CSLA objects will block those requests - with an exception by default - but you can call the CSLA authorization methods before trying to get the data to avoid the exceptions, and then it is a business decision as to how you handle that scenario in terms of what gets returned to the caller.

JasonG replied on Friday, October 08, 2010

Sounds simple enough, but why was i confused.. I think its because I'm using a "Translator" class instead of the DataMapper.  In the Project Tracker app, the "Resources" are excluded when calling the DataMapper, so the child object would be handled like this.. "CSLA.Data.DataMapper.Map(project.Resouces, result.Resource);" ??

 

 

 

  

RockfordLhotka replied on Friday, October 08, 2010

If the business object graph has parent-child relationships, you'll typically end up mapping the parent into the data contract, then mapping its children into the data contract, then moving on to the next parent, etc.

JasonG replied on Friday, October 08, 2010

so not like in my previous post, but map one child at a time in a loop?

RockfordLhotka replied on Friday, October 08, 2010

DataMapper maps one object to another, it doesn't operate on lists. So it is up to you to do the looping, or use some other object-to-object mapper that supports lists (if one exists).

Copyright (c) Marimer LLC