Session: How to Defer Operations

Operations can be deferred till SaveChanges is called by using Defer method in Advanced session operations. All of the operations will update session state appropriately after SaveChanges is called.

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)
    );