Rune Hammerskov
Rune Hammerskov

Reputation: 85

How to model structures such as family trees in document databases

I have been looking into document databases, specifically RavenDb, and all the examples are clear and understandable. I just can't find any example where we do not know beforehand how many levels a given structure has. As an example how would you persist a family tree given the following class:

public class Person{
     public string Name {get;set;} 

     public Person Parent {get;set;}
     public Person[] Children {get;set;}
}

In most examples I have seen we search for the aggregate root and make into a document. It is just not so obvious here what the aggregate root and boundary is.

Upvotes: 4

Views: 1552

Answers (2)

Matt Warren
Matt Warren

Reputation: 10291

Ayende has just posted a blog post that answers this.

Upvotes: 3

Peter
Peter

Reputation: 14108

I guess for RavenDb, you'd have to keep the Ids in your object:

public class Person {
    public string Name { get; set; }
    public string ParentId { get; set; }
    public string[] ChildrenIds { get; set; }
}

Check this page, especially at the bottom, for more info: http://ravendb.net/documentation/docs-document-design

Upvotes: 2

Related Questions