0

我需要在我的 Raven 数据库中存储对实体的任意引用。有时实体是聚合根(参见下面的事件),有时它是值实体(参见下面的会话)。我目前正计划将引用存储为 Lucene 查询(或类似 Lucene 的语法)。有没有人做过这样的事情?我走在一条艰难的道路上吗?

我的一些担忧是:

  • 价值实体不太可能提供标识符,我可以期望可靠地引用价值实体吗?
  • 单个实体应该不知道(与)任意关系基础设施,从复杂对象图中推断查询的最佳方法是什么?
  • 将关系限制为仅聚合根(并防止对值实体的引用)会简化问题,但这需要我重新构建我的事件/会话文档。我希望这两个系统保持分离(对一个系统的担忧不应影响另一个。)

我在下面包含了示例文档来说明我的场景。任何想法、想法、指导或示例将不胜感激。

Events Collection
{
  Id: “30f6...54a7”,
  Title: “Annual Meeting”
  Sessions: [
    { 
      Code: “COM001”, 
      Title: “Opening Ceremony” 
    },
    { 
      Code: “TEC201”, 
      Title: “Intermediate Tech” 
    }
  ]
}

People Collection
{
  Id: "45a8...f209",
  Name: "Chad"
}

Arbitrary Relationships Collection
{
  Id: “b613...8ebb”,
  SubjectEntityQuery: "People.Id:45a8...f209",
  TargetEntityQuery: “Events.Id:30f6...54a7.Sessions,Code:COM001”,
  Action: "Attended Session",
  Story: "Chad attended the Opening Ceremony session"
}

编辑

我想提供更多关于任意关系的细节。我们将有能力扩展系统以响应系统事件并记录两个实体之间的交互。我们拥有比事件、会话和人员更多的实体。这种关系可能是一个人分享一个链接或关于标签的推文。实际上,任意关系集合变成了一个类似图形的结构,允许我们查看给定实体的所有交互。

4

1 回答 1

2

This is screaming relational design.

The easiest way to do this is make the Relationship an object and its Subject and Target fields an array of strings holding IDs of the actual documents it references. This way you can take advantage of Includes to load them along with the relationship document. Eitherway, I don't see how storing a Lucene query syntax helps here.

There may be a better way to model this, but it really depends on your business model and on the thing you are trying to achieve.

Also, you might want to get rid of GUID IDs, just use Raven's conventions.

于 2013-05-16T00:45:20.460 回答