如何在同步的NoSQL数据库(ravendb)的变化 [英] How to synchronize changes in nosql db (ravendb)

查看:171
本文介绍了如何在同步的NoSQL数据库(ravendb)的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始对RavenDB的例子学习的NoSQL。我已经开始与一个简单的模型,假设我们有由用户创建的内容:

I've started learning NoSQL on an example of RavenDB. I've started with a simplest model, let's say we have topics that were created by users:

public class Topic
{
    public string Id { get; protected set; }
    public string Title { get; set; }
    public string Text { get; set; }

    public DenormalizedUser User { get; set; }
}

public class DenormalizedUser
{
    public string Id { get; set; }
    public string Name { get; set; }
}

public class User
{
    public string Id { get; protected set; }
    public string Name { get; set; }
    public DateTime Birthdate { get; set; }

    //some other fields
}

我们不要'T需要整个用户显示一个主题,所以我就非规范化为 DenormalizedUser ,包含编号名称

We don't need the whole User for displaying a Topic, so I've denormalized it to DenormalizedUser, containing an Id and a Name.

所以,这里的问题:

1),这是方法正确的NoSQL的

1) Is this approach correct for NoSQL?

2)如何处理情况下,当用户更改名称?我需要在非规范化的类来手动更新所有的名称字段?

2) How to handle cases when User changes the Name? Do I need to manually update all the Name fields in denormalized classes?

推荐答案

Shaddix可以使用乌鸦DB包含函数加载使用userid从你的话题的用户。

Shaddix you can use the Raven DB Include function to load the User using the UserId from your topic.

var topic = _session.Load<Topic>(topicId)
                    .Customize(x => x.Include<Topic>(y => y.UserId));

var user = _session.Load<User>(topic.UserId);



为主题的负荷将'预'用户和两个负载只会导致一个GET请求。 (我不能直接回答你的回应Ayende由于我的名声)。

The Load for Topic will 'preload' the User and both Loads will only result in one GET request. (I couldn't reply directly to your response to Ayende due to my reputation).

您还可以使用替代(也可能是更清晰).INCLUDE()没有自定义功能()。

You also use the alternative (and probably clearer) .Include() function without Customize().

HTTP: //docs.ravendb.net/consumer/querying/handling-document-relationships.html

这篇关于如何在同步的NoSQL数据库(ravendb)的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆