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

Listeners: What are delete listeners and how to work with them?

IDocumentDeleteListener interface which needs to be implemented if a user wants to add a custom logic or an action when a delete operation is executed. The interface contains only one method that is invoked before the delete request is sent to the server:

public interface IDocumentDeleteListener
{
	/// <summary>
	/// Invoked before the delete request is sent to the server.
	/// </summary>
	/// <param name="key">The key.</param>
	/// <param name="entityInstance">The entity instance.</param>
	/// <param name="metadata">The metadata.</param>
	void BeforeDelete(string key, object entityInstance, RavenJObject metadata);
}

Example

To prevent anyone from deleting documents we can create PreventDeleteListener with can be implemented as follows:

public class PreventDeleteListener : IDocumentDeleteListener
{
	public void BeforeDelete(string key, object entityInstance, RavenJObject metadata)
	{
		throw new NotSupportedException();
	}
}