Session: How to Clear a Session

To clear session state, stop tracking entities, and remove all pending commands, use the clear() method from the advanced session operations.

Syntax

session.advanced.clear();

Example

const employee = new Employee();
employee.firstName = "John";
employee.lastName = "Doe";
await session.store(employee);

session.advanced.clear();

await session.saveChanges(); // nothing will hapen