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 tosession.Advanced.RegisterForConcurrencyCheck().
Learn more in Conditionally save changes based on a document not loaded into the session. -
In this article:
Get entity change vector
- Sync
- Async
Employee employee = session.Load<Employee>("employees/1-A");
string changeVector = session.Advanced.GetChangeVectorFor(employee);
Employee employee = await asyncSession.LoadAsync<Employee>("employees/1-A");
string changeVector = asyncSession.Advanced.GetChangeVectorFor(employee);
Syntax
string GetChangeVectorFor<T>(T instance);
| Parameter | Type | Description |
|---|---|---|
| instance | T | A tracked entity whose change vector will be returned. |
| Return value | Description |
|---|---|
string | The 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. |