如何在文档数据库中建模家谱等结构(How to model structures such as family trees in document databases)

我一直在研究文档数据库,特别是RavenDb,并且所有示例都清晰易懂。 我找不到任何事先我们不知道给定结构有多少级别的例子。 举个例子,如果给出以下类,你将如何持久保存一个家谱:

public class Person{ public string Name {get;set;} public Person Parent {get;set;} public Person[] Children {get;set;} }

在大多数示例中,我看到我们搜索聚合根并将其转换为文档。 在这里,根本和边界的总和不是很明显。

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.

最满意答案

我想对于RavenDb,你必须将Ids保存在你的对象中:

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

查看此页面,尤其是底部,以获取更多信息: http : //ravendb.net/documentation/docs-document-design

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

更多推荐