Skip to main content

Include Compare Exchange Values

  • Compare Exchange Values can be included in Session.Load calls and in queries.

  • The Session tracks Compare Exchange Values, which means that after it has been included, the value can be accessed and modified in that Session without requiring an additional call to the server.

  • The Compare Exchange include syntax is based on the include builder.

  • In this page:

Syntax

Include builder

Chain the method IncludeCompareExchangeValue() to include compare exchange values along with Session.Load() or LINQ queries.

public interface ICompareExchangeValueIncludeBuilder<T, out TBuilder>
{
TBuilder IncludeCompareExchangeValue(string path);

TBuilder IncludeCompareExchangeValue(Expression<Func<T, string>> path);

TBuilder IncludeCompareExchangeValue(Expression<Func<T, IEnumerable<string>>> path);
}
ParameterTypeDescription
pathstring;
Expression<Func<T, string>>;
Expression<Func<T, IEnumerable<string>>>The key of the compare exchange value you want to include, a path to the key, or a path to a string[] of keys.

RQL

In an RQL query, you can use the include keyword followed by cmpxchg() to include a compare exchange value:

include cmpxchg(key)

In javascript functions within queries, use includes.cmpxchg() (see the RawQuery example below):

includes.cmpxchg(key);
ParameterTypeDescription
keystring;
path to stringThe key of the compare exchange value you want to include, or a path to the key.

Examples

using (IDocumentSession session = documentStore.OpenSession())
{
// Load a user document, include the compare exchange value
// with the key equal to the user's Name field
var user = session.Load<User>("users/1-A",
includes => includes.IncludeCompareExchangeValue(
x => x.Name));

// Getting the compare exchange value does not require
// another call to the server
var value = session.Advanced.ClusterTransaction
.GetCompareExchangeValue<string>(user.Name);
}