FetchChildren : Why Call DataPortal.Create<T> of Child ?

FetchChildren : Why Call DataPortal.Create<T> of Child ?

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


JoOfMetL posted on Thursday, September 07, 2006

Hello I use the template of CodeSmith.  

 I have one:       
    EditableRoot       
    EditableChildList       
    EditableChild   

When I call the static method  :
    GetXXX
the method call method Fetch then FetchChildren  

 .....   

and foreach Children :

T child = DataPortal.Create<T> (); 
child. Fetch (Dr.); 
return child;   

So, the method :

        [RunLocal]
        protected override void DataPortal_Create(Object criteria) 
        {
            MarkAsChild();          
        }

of each of my child is call.

But by is defect, the method is marked like RunLocal, if I am not mistaken, this code is run on the server, each child will be sent on the Client to run the code, then to be turned on the server ?

Useless transport of data

perhaps can be to replace  : T child = DataPortal.Create<T>(); by call the defaut constructor of the object ?

Is a this error, or my reasoning is bad?


RockfordLhotka replied on Thursday, September 07, 2006

I'm not familiar with the CS templates, so someone else will have to step in there.

But in general, the data portal is only used to interact with the root object. The child collection and child objects are all loaded by calling an internal method - NOT DataPortal_Create() or DataPortal_Fetch().

So the problem you are talking about does not exist, because the data portal is not used to call the methods on the child objects.

JoOfMetL replied on Thursday, September 07, 2006

 It agrees what I thought that :

'The child collection and child objects are all loaded by calling an internal method - NOT DataPortal_Create() or DataPortal_Fetch().'

 I will defer the problem on the forum CSLA NET Contrib.

Thank you

Brian Criswell replied on Thursday, September 07, 2006

RockfordLhotka:
I'm not familiar with the CS templates, so someone else will have to step in there.

But in general, the data portal is only used to interact with the root object. The child collection and child objects are all loaded by calling an internal method - NOT DataPortal_Create() or DataPortal_Fetch().

So the problem you are talking about does not exist, because the data portal is not used to call the methods on the child objects.

I remember when you made a 1.x change and recommended that every new object, child or root went through the DataPortal.Create method.  What changed?

rasupit replied on Thursday, September 07, 2006

JoOfMetL,

Unless I'm missing something, but how would you call the default constructor from base/abstract class.

The generated code that you've described is for User-Base class scenario.  The DataPortal.Create method was use as a convinience way to instantiate an object from the base class; otherwise you need to write your own reflection code to do that.

Other solution is to move the method to user class, which the place where you can use private contructor.  To me this is not too favorable compare to the current solution.

Ricky Supit

JoOfMetL replied on Friday, September 08, 2006


Hello Ricky Supit,

I did not seek the best manner yet to replace DataPorta_Create.

The problem for me, it is the fact tocall DataPortal_Create for a child, when I use the Fetch method for EditableRoot. I don't know what occurs for CSLA, since the method is marked like RunLocal, and if understood this code well is run on the server ?

Is it annoying ?

Copyright (c) Marimer LLC