How can I use this.Parent.Parent?

How can I use this.Parent.Parent?

Old forum URL:

Mr X posted on Wednesday, August 17, 2011


I have the following object graph:

-       BusinessBase<List>

o    BusinessListBase<ListCultures>

§  BusinessBase<ListCulture>     

o    BusinessListBase<ListItems>

§  BusinessBase<ListItem>

§  BusinessListBase<ListItemLiterals>

·         BusinessBase<ListItemLiteral>

 I need to update ListItemLiterals when data in ListCultures is added, removed or updated to keep them in sync (Ex, when a new culture is associated to the list, all its listitems should provide a new ListItemLiteral to hold a new literal for each listitem). Although it would be a broken business rule if the lists did not match, I do not think this falls in this category because I do not want just to validate that they match, I want to actually modify one based on the other.

I am trying to do this by accessing the root from a child.  I read in one of Rocky's answers to a post that there is a new feature in CLSA 4 that allows programmers to access the parent and grandparents by simply calling this.Parent.Parent.etc... I have tried it and can not get higher than the immediate parent collection. Unfortunatly, I can not find more information about it. Please help.


RockfordLhotka replied on Wednesday, August 17, 2011

The Parent property returns an IParent, and that interface doesn't have a Parent property. You will need to cast the Parent property to some more detailed type so you can navigate higher.

Lord02 replied on Monday, October 29, 2012

Hi Rocky,

I found this thread ... and it's exactly what I'm trying,

can you give me a CODE example on how to get the grand-parent ??

was trying like this:

 var tester = (SecondFactorCredentialsthis.Parent;
 // tester.Parent <---- Not available, I wanted to get the grandparent of this here!!!
and like this:

 test = (BusinessBase<SecondFactorCredentials>) this.Parent; // test.Parent <---- Not available, I wanted to get the grandparent of this here!!!

The following shows the class hierarchy:
DomainModel ( which extends BusinessBase ) <--- this is the grandparent I'm trying to get hold of using this.Parent.GrandParent
- SecondFactorCredentials which also extends BusinessBase <---- the "father"
- UsernamePasswordCredentials which also extends BusinessBase <--- the "grandchild" and "this" in the code above

"this" in the code, child:
public class UserNamePasswordCredentials : LogOnCredentials<UserNamePasswordCredentials>
public abstract class LogOnCredentials<T> : ExtendedBusinessBase<T>, ILogOnCredentials where T : LogOnCredentials<T>

the "father":
 class SecondFactorCredentials : LogOnCredentials<SecondFactorCredentials>, IMutuallyExclusiveCredential  
the Grandfather:
 class LogOnProcessManager : ExtendedBusinessBase<LogOnProcessManager>, ILogOnProfileInformation

thaehn replied on Tuesday, October 30, 2012

Like Rocky just cast it to the proper type like this:

CommonMatrixList statusList = ((PickingEditRoot) ((PickingEditPurchaseOrderItem) ((PickingEditPurchaseOrderLineList) target.Parent).Parent).Parent).PoLineStatusList;

Copyright (c) Marimer LLC