How to synchronize changes in nosql db (ravendb)

别说谁变了你拦得住时间么 提交于 2019-12-05 21:40:16

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);

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).

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

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

shaddix, You don't need to denormalize, you can hold a reference to the id and then Include that when you load from the server

1) Yes, this approach works fine and the result is, that you only need to load the topic-document when you want to display it along with the name of its user. However, as Ayende states, the perfomance will be nearly the same as if you didn't denormalize the user and just include it when needed. If you don't worry about multiple-server deployment I recommend that approach.

2) If you really want to denormalize the user, then you can update all topics referencing this user simply with a set based operation. Look at this: http://ravendb.net/faq/denormalized-updates

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!