How to model structures such as family trees in document databases
-
28-09-2019 - |
Pergunta
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.
Solução
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
Outras dicas
Ayende has just posted a blog post that answers this.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow