You are currently browsing legacy 4.1 version of documentation. Click here to switch to the newest 5.1 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Session: How to Get Entity ID

Entities does not have to contain an ID property or field. In the case of such an entity, and a need for knowing under what ID it is stored on the server, the GetDocumentId method was created.


string GetDocumentId(object entity);
entity object Instance of an entity for which an ID will be returned
Return Value
string Returns the ID for a specified entity. The method may return null if entity is null, isn't tracked, or the ID will be generated on the server.


public class Comment
	public string Author { get; set; }

	public string Message { get; set; }

string commentId = session
	.GetDocumentId(comment); // e.g. comments/1-A