Child fetch has no knowledge of Parent?

Child fetch has no knowledge of Parent?

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


Ranjini posted on Monday, January 17, 2011

 

Using - CSLA 4/Silverlight 4

Is it intentional that the child_fetch method of an object has this.Parent=null? If it is, why so and what is the recommended method of accessing Parent object in the child_fetch method?

Thanks

Ranjini

RockfordLhotka replied on Monday, January 17, 2011

Yes, this is intentional. Child_Fetch is called as the object is being created, and before it has been added as a child to its parent.

This is a no-win situation. If I reversed the order, and added an unintialized object to the parent, the parent's rules would run against an empty object and that'd cause all sorts of issues.

The way it works is not accidental - there are fewer scenarios where a child uses the parent during initiazliation than where the parent runs rules as a child is added.

Beyond that, there's an easy workaround, which is for the parent to pass itself as a parameter to the CreateChild method, in which case the child will have a reference to the parent within the Child_Fetch method.

Ranjini replied on Monday, January 17, 2011

Thanks for taking the time to clarify. It makes perfect sense..

Copyright (c) Marimer LLC