Self-Referencing Hierarchical Data

Self-Referencing Hierarchical Data

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


GregDobbs posted on Wednesday, July 16, 2008

I am developing a chart of accounts application that uses two types of accounts:

1) Posting Accounts that allow transaction entry

2) Rollup Accounts that consolidate Posting Account data.

The table structure for the accounts uses a self-referencing PK structure; AccountKey and ParentAccountKey.

There is no predefined limit on nesting levels. Thus, a Rollup Account might contain a few Posting Accounts as children, along with a few Consolidation Accounts that also have children and perhaps Consolidation Accounts as well.

 I plan on using a Treeview in the UI to allow users to create Charts of Accounts.

This seems to be a complex issue in building using the CSLA framework since if a parent RollupAccount is new, it has no PK to populate the child accounts with. (I use a temporary key system, where new objects are populated with a negative-number temporary key until they get their real PK in the save process. Thus, children can't be assigned the ParentAccountKey until AFTER the save of the parent.)

Has anyone encountered a similar situation, and is there any elegant method to implementing this type of self-referencing structure in BOs?

sergeyb replied on Wednesday, July 16, 2008

If I follow this correct, I did implement this one time.

I had classes: Account, AccountList.  One of the properties in Account class was AccountList (for sub-accounts).  Unique ID of the parent is not really a problem as long as you can get to it before updating a child.  You just pass a parent ID (or parent) to each list’s update method.  I did this in 2.1 though, and never tried in 3.5.  On new accounts GetIDValue would return a temporary ID, such as GUID. 

 

 

 

Sergey Barskiy

Senior Consultant

office: 678.405.0687 | mobile: 404.388.1899

Magenic ®

Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: GregDobbs [mailto:cslanet@lhotka.net]
Sent: Wednesday, July 16, 2008 1:42 PM
To: Sergey Barskiy
Subject: [CSLA .NET] Self-Referencing Hierarchical Data

 

I am developing a chart of accounts application that uses two types of accounts:

1) Posting Accounts that allow transaction entry

2) Rollup Accounts that consolidate Posting Account data.

The table structure for the accounts uses a self-referencing PK structure; AccountKey and ParentAccountKey.

There is no predefined limit on nesting levels. Thus, a Rollup Account might contain a few Posting Accounts as children, along with a few Consolidation Accounts that also have children and perhaps Consolidation Accounts as well.

 I plan on using a Treeview in the UI to allow users to create Charts of Accounts.

This seems to be a complex issue in building using the CSLA framework since if a parent RollupAccount is new, it has no PK to populate the child accounts with. (I use a temporary key system, where new objects are populated with a negative-number temporary key until they get their real PK in the save process. Thus, children can't be assigned the ParentAccountKey until AFTER the save of the parent.)

Has anyone encountered a similar situation, and is there any elegant method to implementing this type of self-referencing structure in BOs?



GregDobbs replied on Wednesday, July 16, 2008

Hello, Sergey.

Thanks for your reply.

I forgot to mention that I am using CSLA 2.1.

Your solution is good, but I believe it only works for one level of nested account( sub-account).

In other words, what if one of the accounts in the AccountList itself has an AccountList? Then, to refer to it you'd have to use Account.AccountList.Account.AccountList - and to get to an Account in that "sub" AccountList you'd have to use Account.AccountList.Account.AccountList.Account. And so on for more levels. :-)

Any thoughts?

 

sergeyb replied on Wednesday, July 16, 2008

That is true, but why does each account need to care of any accounts beyond ParentList.ParentAccount.  This should be the only ID you need to save.  I could be missing something though….

 

 

Sergey Barskiy

Senior Consultant

office: 678.405.0687 | mobile: 404.388.1899

Magenic ®

Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: GregDobbs [mailto:cslanet@lhotka.net]
Sent: Wednesday, July 16, 2008 2:40 PM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: Self-Referencing Hierarchical Data

 

Hello, Sergey.

Thanks for your reply.

I forgot to mention that I am using CSLA 2.1.

Your solution is good, but I believe it only works for one level of nested account( sub-account).

In other words, what if one of the accounts in the AccountList itself has an AccountList? Then, to refer to it you'd have to use Account.AccountList.Account.AccountList - and to get to an Account in that "sub" AccountList you'd have to use Account.AccountList.Account.AccountList.Account. And so on for more levels. :-)

Any thoughts?

 



GregDobbs replied on Wednesday, July 16, 2008

Hi, Sergey.

Actually, you might have the correct solution here. I am going to do a little experimentation and see if this works. If so I'll post my findings. Meantime, any other thoughts are welcome!

Thanks again!.

 

Copyright (c) Marimer LLC