Get Revisions Operation



Get all revisions

// Define the get revisions operation, pass the document id
var getRevisionsOp = new GetRevisionsOperation<Company>("Companies/1-A");

// Execute the operation by passing it to Operations.Send
RevisionsResult<Company> revisions = documentStore.Operations.Send(getRevisionsOp);

// The revisions info:
List<Company> allRevisions = revisions.Results; // All the revisions
int revisionsCount = revisions.TotalResults;    // Total number of revisions
// Define the get revisions operation, pass the document id
var getRevisionsOp = new GetRevisionsOperation<Company>("Companies/1-A");

// Execute the operation by passing it to Operations.Send
RevisionsResult<Company> revisions = await documentStore.Operations.SendAsync(getRevisionsOp);

// The revisions info:
List<Company> allRevisions = revisions.Results; // All the revisions
int revisionsCount = revisions.TotalResults;    // Number of revisions

Paging results

  • Get and process revisions, one page at a time:

var start = 0;
var pageSize = 100;

while (true)
{
    // Execute the get revisions operation
    // Pass the document id, start & page size to get
    RevisionsResult<Company> revisions = documentStore.Operations.Send(
        new GetRevisionsOperation<Company>("Companies/1-A", 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;
}
var start = 0;
var pageSize = 100;

while (true)
{
    // Execute the get revisions operation
    // Pass the document id, start & page size to get
    RevisionsResult<Company> revisions = await documentStore.Operations.SendAsync(
        new GetRevisionsOperation<Company>("Companies/1-A", 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;
}
  • The document ID, start & page size can be wrapped in a Parameter object:

var parameters = new GetRevisionsOperation<Company>.Parameters
{
    Id = "Companies/1-A",
    Start = 0,
    PageSize = 100
};

RevisionsResult<Company> revisions = documentStore.Operations.Send(
    new GetRevisionsOperation<Company>(parameters));
var parameters = new GetRevisionsOperation<Company>.Parameters
{
    Id = "Companies/1-A",
    Start = 0,
    PageSize = 100
};

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

Syntax

Available overloads:

// Get all revisions for the specified document:
public GetRevisionsOperation(string id);

// Page revisions:
public GetRevisionsOperation(string id, int start, int pageSize);
public GetRevisionsOperation(Parameters parameters)
Parameter Type Description
id string Document ID for which to get revisions
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
{
    public string Id { get; set; }     // Document ID for which to get revisions
    public int? Start { get; set; }    // Revision number to start from
    public int? PageSize { get; set; } // Number of revisions to get
}
Return value of store.Operations.Send(getRevisionsOp)
RevisionsResult<T> Object with revisions results

public class RevisionsResult<T>
{  
  public List<T> Results { get; set; }  // The retrieved revisions
  public int TotalResults { get; set; } // Total number of revisions that exist for the document
}