You are currently browsing legacy 1.0 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

Working Asynchronously

The RavenDB client API supports executing the common operations asynchronously, so lengthy operations don't have to be blocking. This is also how the RavenDB Silverlight client is working.

The TPL support is using System.Threading.Tasks, a good intro to which can be found here.

var entity = new Company { Name = "Async Company #2", Id = "companies/2" };
using (var session = documentStore.OpenAsyncSession())
	var company = session.LoadAsync<Company>(1); // loading an entity asynchronously

	session.Store(entity); // in-memory operations are committed asynchronously when calling SaveChangesAsync
	session.SaveChangesAsync(); // returns a task that completes asynchronously

	var query = session.Query<Company>()
		.Where(x => x.Name == "Async Company #1")
		.ToListAsync(); // returns a task that will execute the query