Session: How to Refresh an Entity
To update an entity with the latest changes from the server, use the Refresh
method
from Advanced
session operations.
Syntax
void Refresh<T>(T entity);
Parameter | Type | Description |
---|---|---|
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 a transient entity (not attached) or an entity that was deleted on server-side will result in a InvalidOperationException
.