RavenDB and Recursive Includes

171 views Asked by At

I have a structure

class Node {
    List<string> ChildrenIds;
    ...
}

That I currently store and lookup in RavenDB but Include for results only lets me include down one level in the potentially many leveled tree. Is there any way to tell it to lookup recursively all of these Nodes referenced from the top level?

I know indexes can be used recursively but I wasn't clear on how best to use that to load the correct documents, is it possible to somehow do an Include on an index property?

1

There are 1 answers

2
Ayende Rahien On

Yes, you use the JS support in the query, like so:

declare function recursiveInclude(n){
    for(var i = 0; i<n.ChildrenIds.length; i++)
        recursiveInclude(load(n.ChildrenIds[i]));
    return n;
}
from Node as n
select recursiveInclude(n)