You are currently browsing legacy 3.0 version of documentation. Click here to switch to the newest 4.2 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Session: How to mark entity as readonly?

Entities can be marked as read-only using MarkReadOnly. This operation is equal to adding to entity metadata a key Raven-Read-Only with value set to True.

Implications of setting entity as read-only are as follows:

  • change tracking won't apply to such entity
  • forcing updates or deletes (e.g. using Commands) will throw OperationVetoedException

Syntax

void MarkReadOnly(object entity);

Parameters
entity object Instance of an entity that will be marked as read-only.

Example

Employee employee = session.Load<Employee>("employees/1");
session.Advanced.MarkReadOnly(employee);
session.SaveChanges();