Operations: Get and Count Revisions


  • Get and Count a document's revisions using the GetRevisionsOperation store operation.
  • To Count a document's revisions without getting them, use the GetCountFor session method.

  • In this page:


GetRevisionsOperation

Overloads

// Get all the revisions of the document whose ID is provided
public GetRevisionsOperation(string id);

// Start from a specified revision and Get a specified number of revisions
public GetRevisionsOperation(string id, int start, int pageSize);

// Start from a specified revision and Get a specified number of revisions
public GetRevisionsOperation(Parameters parameters)
Parameter Type Description
id string ID of the document whose revisions you want to get
start int Revision number to start from
pageSize int Number of revisions to get
parameters Parameters an object that wraps Id, Start, and PageSize (see below)

public class Parameters
{
    // ID of the document whose revisions you want to get
    public string Id { get; set; }
    // Revision number to start from
    public int? Start { get; set; }
    // Number of revisions to get
    public int? PageSize { get; set; }
}

Return Value: RevisionsResult<T>

public class RevisionsResult<T>
{
  // The retrieved revisions
  public List<T> Results { get; set; }

  // Total number of revisions that exist for this document
  public int TotalResults { get; set; }
}

Usage Samples

Get all the revisions created for a document

RevisionsResult<Company> revisions = await documentStore.Operations.SendAsync(
        // get all the revisions for this document
        new GetRevisionsOperation<Company>(company.Id));

List<Company> retrievedRevisions = revisions.Results;
int revisionsCount = revisions.TotalResults;

Get and process revisions, one page at a time

var start = 0;
var pageSize = 100;
while (true)
{
    RevisionsResult<Company> revisions = await documentStore.Operations.SendAsync(
        new GetRevisionsOperation<Company>(company.Id, start, pageSize));
    {
        // process the retrieved revisions here
    }
    if (revisions.Results.Count < pageSize)
        break; // no more revisions to retrieve

    // increment 'start' by page-size, to get the "next page" in next iteration
    start += pageSize;
}

You can also pass the method the ID, Start, and PageSize arguments wrapped in a Parameters object:

var parameters = new GetRevisionsOperation<Company>.Parameters
{
    Id = company.Id,
    Start = 0,
    PageSize = 100
};

RevisionsResult<Company> revisions = await documentStore.Operations.SendAsync(
    new GetRevisionsOperation<Company>(parameters));