see on GitHub

Session : Saving changes

Pending session operations e.g. Store, Delete and many others will not be send to server till SaveChanges is called.

Syntax

void SaveChanges();

Example

// storing new entity
session.Store(new Employee
	              {
		              FirstName = "John", 
					  LastName = "Doe"
	              });

session.SaveChanges();

Waiting for indexes

You can ask the server to wait until the indexes are caught up with this particular write after save changes. You can also set a timeout and whatever to throw or not. You can specify indexes that you want to wait for. If you don't specify anything, RavenDB will automatically select just the indexes that are impacted by this write.

session.Advanced.WaitForIndexesAfterSaveChanges(timeout: TimeSpan.FromSeconds(30));
session.Store(new Employee
{
    FirstName = "John",
    LastName = "Doe"
});

session.SaveChanges();

Waiting for replication

You can ask the server to wait until the replication are caught up with this particular write after save changes.

  • You can also set a timeout and whatever to throw or not.
  • You can specify whether you want to throw on timeout, which may happen in case of network issues.
  • You can specify to how many replicas (nodes) the currently saved write must be replicated, before the SaveChanges() returns.
  • You can specify whether the SaveChanges() will return only when the current write was replicated to majority of the nodes.

session.Advanced.WaitForReplicationAfterSaveChanges(
          timeout: TimeSpan.FromSeconds(30),
          throwOnTimeout: false, //default true
          replicas:2, //minimum replicas to replicate
          majority:false);

session.Store(new Employee
{
    FirstName = "John",
    LastName = "Doe"
});

session.SaveChanges();

Important

The WaitForReplicationAfterSaveChanges waits only replicas which are part of the cluster. This means, for example, that external replication destinations are not counted towards the number specified in replicas parameter, since such destinations are not part of the cluster.