Skip to main content

Include Compare Exchange Values

  • Compare-Exchange items can be included when loading entities and when making queries.

  • The Session tracks the included Compare Exchange items which means their value can be accessed
    in that Session without making an additional call to the server.

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

  • In this page:

Syntax

Include method

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