You are currently browsing legacy 4.0 version of documentation. Click here to switch to the newest 5.1 version.
Session: How to Evict Single Entity from a Session
We can clear all session operations and stop tracking of all entities by the using session.advanced.clear() method, but sometimes there is a need to only to do a cleanup for a single entity. For this purpose
evict() was introduced.
|entity||object||Entity that will be evicted|
const employee1 = new Employee(); employee1.firstName = "John"; employee1.lastName = "Doe"; const employee2 = new Employee(); employee2.firstName = "Joe"; employee2.lastName = "Shmoe"; await session.store(employee1); await session.store(employee2); session.advanced.evict(employee1); await session.saveChanges(); // only 'Joe Shmoe' will be saved
let employee = await session.load("employees/1-A"); // loading from serer employee = await session.load("employees/1-A"); // no server call session.advanced.evict(employee); employee = await session.load("employees/1-A"); // loading from server