Lazy loading of a child property

Lazy loading of a child property

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


barabasy posted on Friday, January 07, 2011

Hello,

 

I have read the Expert Business Object C# 2008 and I really have trouble to understand why we have to use DataPortal.Fetch when lazy loading a child instead of DataPortal.FetchChild? I am referring to Chapter 9. Parent-Child Relationships and in subsection "Enabling lazy loading in the Child Class".

When authoring the child class, we do not know necessarily if someone will lazy load that object. I can choose to always use DataPortal_Fetch and manually call MarkAsChild but is that really equivalent to Child_Fetch? I am really confused. Don't DataPortal.Fetch and DataPortal.FetchChild both trigger a call to the application server and thus all have access to the database?

 

Thank you.

Barabasy

JonnyBee replied on Friday, January 07, 2011

The DataPortal.XYZChild methods will NOT make a call to the server -  only the DataPortal.XYZ methods does.

So to make a call to the server for fetch you must use DataPortal.Fetch - and if lazy loading a child then also make sure to call MarkAsChild.

The DataPortal.XYZChild methods should be called for loading children in the context of a DataPortal.XYZ call.

 

 

Marjon1 replied on Friday, January 07, 2011

Jonny is right about the DataPortal.XYZChild methods not going across the network to the server, it caught me out when they were first introduced.

What we have done to get around this, is to create a command object that calls the DataPortal.XYZChild method for us within the execute method, therefore being sent across the wire and any of our children objects can be lazy loaded as required in the future.

The call looks something like this:

     childObj = LazyLoadCommand.Fetch(Of Child)(Id)  'The paramamater is actual a paramArray that is just passed to the relevant child method.

 

barabasy replied on Tuesday, January 11, 2011

Thank you for your quick answer and suggestion. Using a command is indeed a good idea. I am still new to CSLA so having such tips is well appreciated.

Cheers.

Barabasy

barabasy replied on Tuesday, January 11, 2011

Thank you for your insigh Jonny. I really appreciate the quick response I got from the community. This is really great.

 

barabasy

Copyright (c) Marimer LLC