Recursive collections

Posts   
 
    
Adi
User
Posts: 1
Joined: 15-Aug-2006
# Posted on: 15-Aug-2006 20:36:32   

I am trying to contemplate on whether to use a O/R Mapper or not for my project and found LLBLGen Pro quite nice. I was trying to do a sample project for one of my tables which for some reason was designed in the following way: It has the following fields: HIERARCHY_ID PK - Mapped to another table NODE_ID PK PARENT_NODE_ID

Right now, I make use of the datatable to retrieve the records and populate my collection in such a way that I get a RootNode for the hierarchy and the RootNode becomes the first ParentNode for its childs. This RootNode contains a collection of its childnodes and the childnodes contains their childs collection. I use this collection to create a tree.

Can you please help me on how to achieve this using LLBLGen Pro?

Also, I have another question. Currently my application contains these layers: WinForms Layer -> Win UI Controls Layer -> FrameWork Layer -> Security Layer -> DAL. The reason for me to have so many layers is because the users will be able to make use of the Framework and the WinUI controls layer and write custom code from the application.

Can you please let me know how to make use of this tool with minimum changes to my app?

Thanks, Adi

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 16-Aug-2006 07:40:06   

For a tree like hierarchy, you just need to fetch the root node(s) , and with the use of prefetchPaths you'll be able to fetch it's direct children, and again with subPaths you would get the next level of children. All these are fetched in one go (upon fetching the root node).

You can decide to which level you want to dig deep. Please refer to the LLBLGen Pro manual "Using the generated code -> Adapter/SelfServicing -> Prefetch paths" reference:[http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=4211](http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=4211)

Or you can fetch the entire table in one collection and build the tree in a hash table which keeps track of entity - node pairs. reference: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=4928

And for the layers question, LLBLGen Pro can contribute to the DAL layer and it creates your business objects to be used in the BL (Low Level BL). Also it depends on what you do in the security layer, you may ad your security code to the code generation templates to be generated for you in the DAL layer or in the Business Objects Layer.