You are currently browsing legacy 3.5 version of documentation. Click here to switch to the newest 5.1 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Session: How to evict single entity from a session?

We can clear all session operations and stop tracking of all entities by using Clear method, but sometimes there is need to only to do a cleanup only for one entity. For this purpose Evict was introduced.


void Evict<T>(T entity);
entity T Instance of an entity that will be evicted

Example I

Employee employee1 = new Employee
		              FirstName = "John", 
					  LastName = "Doe"

Employee employee2 = new Employee
		              FirstName = "Joe", 
					  LastName = "Shmoe"



session.SaveChanges(); // only 'Joe Shmoe' will be saved

Example II

Employee employee = session.Load<Employee>("employees/1"); // loading from server
employee = session.Load<Employee>("employees/1"); // no server call
employee = session.Load<Employee>("employees/1"); // loading from server