Skip to main content

How to Get Entity Change-Vector

  • A change vector identifies a document version across the database group.
    RavenDB updates the change vector whenever the document changes.

  • When a session tracks a document loaded directly or returned by a query, it tracks both the entity and the document's change vector. If the session saves changes to the document, it updates the tracked change vector.

  • Use session.Advanced.GetChangeVectorFor() to retrieve the tracked change vector.
    The entity must be tracked by the session.

  • To make another session's SaveChanges() reject a save if the document has since changed,
    pass the document ID and change vector to session.Advanced.RegisterForConcurrencyCheck().
    Learn more in Conditionally save changes based on a document not loaded into the session.

  • In this article:

Get entity change vector​

Employee employee = session.Load<Employee>("employees/1-A");
string changeVector = session.Advanced.GetChangeVectorFor(employee);

Syntax​

string GetChangeVectorFor<T>(T instance);
ParameterTypeDescription
instanceTA tracked entity whose change vector will be returned.
Return valueDescription
stringThe entity's tracked change vector, or null if the entity is new and has not yet been saved.
Throws an exception if the instance is not tracked by the session.

In this article