You are currently browsing legacy 3.0 version of documentation. Click here to switch to the newest 4.2 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Session: How to refresh entity?

To update entity with latest changes from server Refresh method from Advanced session operations can be used.

Syntax

void Refresh<T>(T entity);

Parameters
entity T Instance of an entity that will be refreshed

Example

Employee employee = session.Load<Employee>("employees/1");
Assert.Equal("Doe", employee.LastName);

// LastName changed to 'Shmoe'

session.Advanced.Refresh(employee);
Assert.Equal("Shmoe", employee.LastName);

Remarks

Refreshing transient entity (not attached) or entity that was deleted on server-side will result in InvalidOperationException.