RavenDB UseOptimisticConcurrency在配置中? [英] RavenDB UseOptimisticConcurrency in Config?

查看:155
本文介绍了RavenDB UseOptimisticConcurrency在配置中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Raven.Server.exe.config中将乐观并发设置为true?还是可以以某种方式在数据库级别应用它?在RavenDB的站点上,我提到了一些设置UseOptimisticConcurrency = true的内容,但是看起来好像是在代码中的会话级别:

Is there a way to set optimistic concurrency to true in Raven.Server.exe.config? Or, can it somehow be applied at the database level? On RavenDB's site, I see a couple of mentions of setting UseOptimisticConcurrency = true, but it looks like it's at the session level within the code:

public void Save<T>(T objectToSave)
{
    using (IDocumentSession session = Database.OpenSession())
    {
        session.Advanced.UseOptimisticConcurrency = true;  // This is the setting
        Guid eTag = (Guid)session.Advanced.GetEtagFor(objectToSave);
        session.Store(objectToSave, eTag);
        session.SaveChanges();
    }
}

我想知道设置是否存在于服务器范围内的某个地方,因此不需要为代码中的每个会话指定该设置.

I would like to know if it that setting exists somewhere server-wide, so it doesn't need to be specified for each session in code.

上面的代码产生以下错误.试图找出原因...

The code above produces the following error. Trying to find out why...

好的,我正在进步.如果检索对象,并在同一会话中所有调用GetEtagFor(),那么我会得到一个有效的eTag.所以我想我现在的主要问题是:在客户端UI中使用会话的正确方法是在应用启动时一次打开该会话,然后在结束时将其关闭吗?而且...存储eTag的正确方法是什么?上面的编码方式是在存储之前立即检索eTag,我想这是错误的方法.我猜应该在首次检索对象时检索eTag.但是,当我们最初获得对象列表时,是否应该遍历每个对象并对其调用GetEtagFor()?似乎不正确...

Edit 2: Ok, I'm making progress. If I retrieve the object, and call GetEtagFor() all within the same session, then I get a valid eTag. So I guess my main question now is: Is the correct way to use a session, within a client UI, to open the session once when the app starts, and then close it at the end? And... What's the correct way to store the eTag? The way it's coded above, the eTag is retrieved right before storing, which I would imagine is the wrong way to do it. I'm guessing the eTag should be retrieved when the object is first retrieved. But when we originally get a list of objects, should we have to loop through each and call GetEtagFor() on them? Doesn't seem right...

推荐答案

鲍勃, 不,在打开会话时需要设置UseOptimisticConcurrency. 不,每个应用程序只有一个会话是错误的事情.有关会话管理的更多详细信息,请参见本文:

Bob, No, UseOptimisticConcurrency is something that you need to setup when you open the session. And NO, a single session per the entire application is the wrong thing to do. See this article for more details on session management:

http://archive.msdn.microsoft.com/mag200912NHibernate

它讨论了NHibernate,但是会话管理部分也适用于ravendb.

It talks about NHibernate, but the session management parts applies to ravendb as well.

这篇关于RavenDB UseOptimisticConcurrency在配置中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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