You are currently browsing legacy 5.0 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 the 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-A"); // loading from server
employee = session.Load<Employee>("employees/1-A"); // no server call
employee = session.Load<Employee>("employees/1-A"); // loading from server