---
title: "Evict a Single Entity from a Session"
url: "https://docs.ravendb.net/6.2/client-api/session/how-to/evict-entity-from-a-session"
version: "6.2"
language: "php"
---

# Evict a Single Entity from a Session

> Client language: PHP. Also available for [C#](https://docs.ravendb.net/6.2/client-api/session/how-to/evict-entity-from-a-session.md), [Java](https://docs.ravendb.net/6.2/client-api/session/how-to/evict-entity-from-a-session.java.md), [Python](https://docs.ravendb.net/6.2/client-api/session/how-to/evict-entity-from-a-session.python.md), [Node.js](https://docs.ravendb.net/6.2/client-api/session/how-to/evict-entity-from-a-session.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

We can clear all session operations and stop tracking of all entities using the
[clear](https://docs.ravendb.net/6.2/client-api/session/how-to/clear-a-session.php.md) method, but sometimes
there's a need to do cleanup only for one entity. This is what `evict` is for.

## Syntax

```php
public function evict(object $entity): void;
```

| Parameter | Type | Description |
| - | - | - |
| **$entity** | `object` | Instance of an entity that will be evicted |

## Example I

```php
$employee1 = new Employee();
$employee1->setFirstName("John");
$employee1->setLastName("Doe");

$employee2 = new Employee();
$employee2->setFirstName("Joe");
$employee2->setLastName("Shmoe");

$session->store($employee1);
$session->store($employee2);

$session->advanced()->evict($employee1);

$session->saveChanges(); // only 'Joe Shmoe' will be saved
```

## Example II

```php
$employee = $session->load(Employee::class, "employees/1-A");//loading from serer
$employee = $session->load(Employee::class, "employees/1-A"); // no server call
$session->advanced()->evict($employee);
$employee = $session->load(Employee::class, "employees/1-A"); // loading form server
```

## See also

- [What is a Session and How Does it Work](https://docs.ravendb.net/6.2/client-api/session/what-is-a-session-and-how-does-it-work.php.md)
- [Clear a Session](https://docs.ravendb.net/6.2/client-api/session/how-to/clear-a-session.php.md)
- [Refresh Entity](https://docs.ravendb.net/6.2/client-api/session/how-to/refresh-entity.php.md)
- [How to Check if Entity has Changed](https://docs.ravendb.net/6.2/client-api/session/how-to/check-if-entity-has-changed.php.md)
