RavenDB 建模 1 到多个文档

发布于 2024-12-09 04:21:09 字数 1139 浏览 3 评论 0原文

以这个示例模型为例:

public class Location
{
    public string Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
}

public class Activity
{
    public string Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
}

这些文档之间的关系是一个位置可以没有或有多个活动。比如说伦敦可以有彩弹射击、卡丁车等。

我确实将这些文档放入一个文档中,但是观看和阅读文档和博客时,需要单独访问这些文档。您可以想象每个地点都有一个列出活动的网站页面,以及提供详细信息的活动页面。

示例查询如下:

  • 获取所有位置
  • 获取位置详细信息(从 URL 中给出位置名称)
  • 获取每个位置的所有活动(从 URL 中给出位置名称)
  • 获取活动详细信息(从 URL 中给出位置名称和活动名称)

使用 DenormalizedReference 方法描述于:

http://blogs.sonatribe.com/wayne/2011/07/06/using-denormalized-references-in-ravendb/

(我确实看到了这个,但无法弄清楚语法或者它是否满足我的需要

http://ravendb.net/faq/denormalized-references

似乎有点适合我的场景。但是,当使用上述类型制作演示项目时,我注意到如果我更改了位置名称,它不会在活动中更改它。保持文档同步是一件大事。

那么我该如何实现这一目标呢?

Take this example model:

public class Location
{
    public string Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
}

public class Activity
{
    public string Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
}

The relationship between these documents is a location can have none or many activities. Say London can have Paintball, Go karting etc.

I did thing to put these documents into one document but watching and reading the documentation and blogs, the documents need to be accessed separately. You can imagine a website page for each location listing activities and activity pages giving the details.

Example queries would be:

  • Fetch all locations
  • Fetch a locations details (given Location name from URL)
  • Fetch all activities per location (given Location name from URL)
  • Fetch an activities details (given Location name & Activity name from URL)

Using the DenormalizedReference method described at:

http://blogs.sonatribe.com/wayne/2011/07/06/using-denormalized-references-in-ravendb/

(and I did see this but couldn't figure out the syntax or if it does what I need

http://ravendb.net/faq/denormalized-references
)

Seems to kind of fit my scenarios. But when making a demo project with the above types I noticed if I changed a location name it didn't change it in the activity. Keeping the documents in sync is a big thing.

So how do I achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

属性 2024-12-16 04:21:09

Phil,

  • 活动中有一个字符串 LocationId 属性,它允许您查询它们。
  • 将活动作为集合存储在位置中可能会更容易(因此它们不是单独的文档,而是嵌入其中)。

Phil,

  • have a string LocationId property in the Activity, that would allow you to query for them.
  • it would be easier probably to just store the activities as a collection inside the Location (so they aren't a separate document, but are embedded inside).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文