see on GitHub

Session : Opening a Session

To open synchronous session use the OpenSession method from DocumentStore or OpenAsyncSession if you prefer working in an asynchronous manner.

Syntax

There are three overloads of OpenSession method

// Open session for a 'default' database configured in 'DocumentStore'
IDocumentSession OpenSession();

// Open session for a specified database
IDocumentSession OpenSession(string database);

IDocumentSession OpenSession(SessionOptions options);

The first method is an equivalent of doing

store.OpenSession(new SessionOptions());

The second method is an equivalent of doing

store.OpenSession(new SessionOptions
{
    Database = databaseName
});

Parameters
options OpenSessionOptions Options containing information such as name of database and RequestExecutor.
Return Value
IDocumentSession Instance of a session object that implements IDocumentSession interface.

Example I

using (IDocumentSession session = store.OpenSession())
{
    // code here
}

Example II

using (IAsyncDocumentSession session = store.OpenAsyncSession())
{
    // async code here
}

Important

Always remember to release session allocated resources after usage by invoking the Dispose method or wrapping the session object in the using statement.