Session: How to get entity Id?

Entities does not have to contain Id property or field. In case of such an entity and a need of knowing under what Id it is stored on server GetDocumentId method has been created.

Syntax

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

Example

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

	public string Message { get; set; }
}

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