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

Session: How to Defer Operations

Operations can be deferred till SaveChanges is called by using Defer method in Advanced session operations. There are six types of commands that can be deferred:

Syntax

void Defer(ICommandData command, params ICommandData[] commands);
void Defer(ICommandData[] commands);

Parameters
ICommandData Command to be executed.  
ICommandData[] Array of commands implementing ICommandData interface.  

Example

session
    .Advanced
    .Defer(
        new PutCommandData("products/999-A", null, new DynamicJsonValue
        {
            ["Name"] = "My Product",
            ["Supplier"] = "suppliers/999-A",
            ["@metadata"] = new DynamicJsonValue
            {
                ["@collection"] = "Users"
            }
        }),
        new PutCommandData("suppliers/999-A", null, new DynamicJsonValue
        {
            ["Name"] = "My Product",
            ["Supplier"] = "suppliers/999-A",
            ["@metadata"] = new DynamicJsonValue
            {
                ["@collection"] = "Suppliers"
            }
        }),
        new DeleteCommandData("products/1-A", null)
    );