---
title: "Session: How to Get and Modify Entity Metadata"
url: "https://docs.ravendb.net/6.2/client-api/session/how-to/get-and-modify-entity-metadata"
version: "6.2"
language: "csharp"
---

# Session: How to Get and Modify Entity Metadata

> Client language: C#. Also available for [Java](https://docs.ravendb.net/6.2/client-api/session/how-to/get-and-modify-entity-metadata.java.md), [Node.js](https://docs.ravendb.net/6.2/client-api/session/how-to/get-and-modify-entity-metadata.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."

When a document is downloaded from the server, it contains various metadata information like ID or current change-vector. This information is stored in a session and is available for each entity using the `GetMetadataFor` method from the `Advanced` session operations.

## Get the Metadata

```csharp
IMetadataDictionary GetMetadataFor<T>(T instance);
```

| Parameters | | |
| - | - | - |
| **instance** | T | Instance of an entity for which metadata will be returned. |

| Return Value | |
| - | - |
| IMetadataDictionary | Returns the metadata for the specified entity. Throws an exception if the `instance` is not tracked by the session. |

### Example

```csharp
var employee = session.Load<Employee>("employees/1-A");
var metadata = session.Advanced.GetMetadataFor(employee);
```

## Modify the Metadata

After getting the metadata from `session.Advanced.GetMetadataFor` you can modify it just like any other dictionary.

> **Note**
>
> Keys in the metadata that starting with @ are reserved for RavenDB use

### Example I

```csharp
var user = new User
{
  Name = "Idan"
};

session.Store(user);
var metadata = session.Advanced.GetMetadataFor(user);
metadata["Permissions"] = "ReadOnly";
session.SaveChanges();
```

### Example II

```csharp
var user = session.Load<User>("users/1-A");
var metadata = session.Advanced.GetMetadataFor(user);

metadata["Permissions"] = "ReadAndWrite";

session.SaveChanges();
```

## 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.md)
- [How to Get Entity Change-Vector](https://docs.ravendb.net/6.2/client-api/session/how-to/get-entity-change-vector.md)
- [How to Get Entity Last Modified](https://docs.ravendb.net/6.2/client-api/session/how-to/get-entity-last-modified.md)
- [Indexing Metadata](https://docs.ravendb.net/6.2/indexes/indexing-metadata.md)
