see on GitHub

Session : How to Enable Optimistic Concurrency

By default, optimistic concurrency checks are turned off. Changes made outside our session object will be overwritten.

Checks can be turned on by setting the UseOptimisticConcurrency property from the Advanced session operations to true, and may cause ConcurrencyExceptions to be thrown.

Another option is to control optimistic concurrency per specific document.

To enable it, you can supply a Change Vector to Store. If you don't supply a 'Change Vector' or if the 'Change Vector' is null, then optimistic concurrency will be disabled.

Setting optimistic concurrency per specific document overrides the use of the UseOptimisticConcurrency property from the Advanced session operations.

Enabling per Session

using (IDocumentSession session = store.OpenSession())
{
    session.Advanced.UseOptimisticConcurrency = true;

    Product product = new Product { Name = "Some Name" };

    session.Store(product, "products/999");
    session.SaveChanges();

    using (IDocumentSession otherSession = store.OpenSession())
    {
        Product otherProduct = otherSession.Load<Product>("products/999");
        otherProduct.Name = "Other Name";

        otherSession.SaveChanges();
    }

    product.Name = "Better Name";
    session.SaveChanges(); // will throw ConcurrencyException
}

Enabling Globally

The first example shows how to enable optimistic concurrency for a particular session. This can be also turned on globally, for all opened sessions by using the convention store.Conventions.UseOptimisticConcurrency.

store.Conventions.UseOptimisticConcurrency = true;

using (IDocumentSession session = store.OpenSession())
{
    bool isSessionUsingOptimisticConcurrency = session.Advanced.UseOptimisticConcurrency; // will return true
}

Turning Off Optimistic Concurrency for a Single Document when it is Enabled on Session

Optimistic concurrency can be turned off for a single document by passing null as a change vector value to Store method even when it is turned on for an entire session (or globally).

using (IDocumentSession session = store.OpenSession())
{
    session.Store(new Product { Name = "Some Name" }, id: "products/999");
    session.SaveChanges();
}

using (IDocumentSession session = store.OpenSession())
{
    session.Advanced.UseOptimisticConcurrency = true;

    session.Store(new Product { Name = "Some Other Name" }, changeVector: null, id: "products/999");
    session.SaveChanges(); // will NOT throw Concurrency exception
}