Single table composition starting from given node

Posts   
 
    
jwijnker
User
Posts: 32
Joined: 09-Mar-2011
# Posted on: 10-Mar-2011 12:24:04   

Is anyone familiar with a compositions using llblgen?

I want to get the tree of nodes from a given starting node.

As you can see below, I tried to use a filter, but in that case I only get one node, without the StartNodeId I always get the conplete list. Is llblgen capable to use this form of recursion? Does anyone know how to get a tree from the given starting node?

(Using LlblGen V3.0)

TableStructure: DossierStatus

  • StateId (PK) (not null)
  • StateName (not null)
  • StateParent (FK --> pointing to other PK in the same table) (null)

TableContents:

1, "State1", NULL 2, "State 2", 1 3, "OtherState", 1

USED CODE:

public IEntityCollection2 GetTree(int StartNodeId) { // Prepare the result collection IEntityCollection2 nodes = new EntityCollection<DossierStatusEntity>();

        // Create an EntityCollection of node entities and attach a context:
        using (DataAccessAdapter adapter = new DataAccessAdapter())
        {
            // Filter doesn't help here
            //IRelationPredicateBucket filter = new RelationPredicateBucket();
            //filter.PredicateExpression.Add(DossierStatusFields.StatusId == StartNodeId);

            // Use a prefetch path to populate the node.Children collection of each node:
            PrefetchPath2 path = new PrefetchPath2((int)EntityType.DossierStatusEntity);
            path.Add(DossierStatusEntity.PrefetchPathDossierChild);

            // Fetch all menu items:
            adapter.FetchEntityCollection(nodes, null, path);
        }
        return nodes;

}

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 10-Mar-2011 12:41:58   
jwijnker
User
Posts: 32
Joined: 09-Mar-2011
# Posted on: 10-Mar-2011 13:29:57   

Walaa wrote:

Have a look at this thread: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=11983

Thanks for your reply, I haven't found that topic. In that case the composition is established separated from llblgen (what would be my alternative). I suppose llblgen can't build the composite hierarchy itself? (due to the chance of infinite loops?)

And there are no possibilities the give the starting node?

Thanks in advance.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-Mar-2011 20:50:14   

No, if you don't know how deep you want to get, that's no possible. You have to do one of the things mentioned in the link posted by Walaa. Other thing you can do is create a stored procedure that makes this for you, then you can fetch that SP with a projection that fills an entity collection.

David Elizondo | LLBLGen Support Team
jwijnker
User
Posts: 32
Joined: 09-Mar-2011
# Posted on: 11-Mar-2011 10:38:53   

Thank you guys! Appreciated!