Async data portal with Child objects

Async data portal with Child objects

Old forum URL:

xetal posted on Thursday, February 11, 2010

I have a business object that contains a lazy loaded collection property.  The collection is loaded async by initializing a DataPortal<T> and calling BeginFetch.  The BeginFetch in turn calls the collection's DataPortal_Fetch method.  My collection should actually be a child, but it is getting loaded by the DataPortal_Fetch.  In the DataPortal_Fetch, I manually call MarkAsChild().  In my root business object, the IsBusy property does not work as expected since the collection is not linked to the parent object until later. 

How come the non-static DataPortal<T> does not provide Child_XYZ methods like BeginChildFetch?  Am I missing something here?  It seems like the async operations only work with root objects then I need to manually MarkAsChild().

RockfordLhotka replied on Thursday, February 11, 2010

The child data portal never moves the calling context across the network. That is entirely outside of the scope of the child data portal.

Lazy loading is somewhat of a special case where you are loading a child, but you (very probably) need to move the calling context across the network. So you have to use the root data portal to do that.

The most elegant solution is to create a command object that runs to the server to create/retrieve the child. So the command object is responsible for going across the network, and the command it executes is a DataPortal.FetchChild() on the server.

Most people short-circuit this by doing what you are doing, which is to implement a DataPortal_Fetch() method in the child object and to explicitly call MarkAsChild() in that method.

But if you want to avoid that messiness, use the command object solution.

xetal replied on Friday, February 12, 2010

Doh.  Thanks!

Calin replied on Friday, February 19, 2010


 Nice ideea do you happen to have a example of this in your videos or the book ?


RockfordLhotka replied on Friday, February 19, 2010

I don't think so.

Copyright (c) Marimer LLC