You are currently browsing legacy 2.0 version of documentation. Click here to switch to the newest 4.2 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 = await session.LoadAsync<Company>(1); // loading an entity asynchronously

	await session.StoreAsync(entity); // in-memory operations are committed asynchronously when calling SaveChangesAsync
	await 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
}