Nhibernate + Recursion = Suck!

I use nhibernate and I want to load a branch of the tree. My tree is not binary, nor doubley linked. Trust me this is bad really bad, you have a couple of options.

  1. Load your whole graph or tree
  2. Make lazy loaded calls one at a time to your tree, or some variation there fore of.
  3. Load your levels.

If you chose option one you probably work for a hardware manfacturer, or don’t have an example, option 2 works if again you batch and have small tree.

Option 3 is the only real solution, and basically you will want to make sure your parent / parent id is loaded and not lazy loaded so you can trigger the next query.

Ex.



Dim myBranch as New List(Of Object)Dim myTree as New List(Of List(Of Object))

Dim myCurrentParentId as Object

'Loop StartmyCurrentParentId = myChildObj.ParentId

myBranch.Add(myChildObj.Id)myTree.Add(NhibernateQuery.List())'This query should be like "FROM Domain.Tree t WHERE t.ParentId = :P arentId

'Loop End

You can then use the branch list to find selected children for displaying levels of tree, or a branch of a tree.

Post a Comment

Your email is never shared. Required fields are marked *

*
*
Profile Picture

About Ian Lintner


I am a software developer, mostly web,  in Des Moines, Iowa. I take a very opinionated stand concerning development, you will never regret a simple design or architecture. My education was at Drake University in Biology and Computer Science. Offline I am recently married to my wife Heather. I try my hand at many hobbies currently I am gardening till the snow comes in.



My Current Projects


Des Moines Twitter Trends