RavenDB 建模 1 到多个文档
以这个示例模型为例:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Phil,
Phil,