RavenDB version 2.5. Other versions:

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
Comments add new comment

The comments section is for user feedback or community content. If you seek assistance or have any questions, please post them at our support forums.

REPLY Posted by mennowar on

I really would like to see this section to be more precise. I'm using Silverlight5 and am really lost because everything there is async.

REPLY Posted by Georgios on

Aren't you missing a load of "await" s?

Ayende Rahien
REPLY Posted by Ayende Rahien on

This code is written for C# 4.0, it would work as it for C# 5.0 with awaits

REPLY Posted by Ryan on

Here is what async with task await looks like.

public static async Task<Token> GetUserToken(string userName) { using (var session = DataDocumentStore.Instance.OpenAsyncSession()) { var token = await session.LoadAsync<Token>(string.Format("UserName/{0}", userName));

            return token;