• Start

Methods

Merge

The .NET SDK for SurrealDB enables simple and advanced querying of a remote or embedded database.

Modifies all records in a table, or a specific record.

Method Syntax
await db.Merge<T>(resource, data)
Note

This function merges the current document / record data with the specified data.

Arguments

Description

thing

The table name or the specific RecordId to merge.

data

The data with which to modify the records.

cancellationToken

The cancellationToken enables graceful cancellation of asynchronous operations.

Merging data within a single record
// Only changes the fields specified in the merge object
var merge = new PersonMerge
{
    Id = ("person", "tobie"),
    Settings = new Settings
    {
        Active = true,
        Marketing = false,
    },
};
var result = await db.Merge<PersonMerge, Person>(merge);

// Only changes the fields specified in the Dictionary
var data = new Dictionary<string, object>
{
    { "tags", new List<string> { "developer", "engineer" } }
};

var result = await db.Merge<Person>(("person", "tobie"), data);
Merging data for every record in a table
// Only changes the fields specified in the merge object
var merge = new PersonMerge
{
    Settings = new Settings
    {
        Active = true,
        Marketing = false,
    },
};
var result = await db.Merge<PersonMerge, Person>("person", merge);

// Only changes the fields specified in the Dictionary
var data = new Dictionary<string, object>
{
    { "tags", new List<string> { "developer", "engineer" } }
};

var result = await db.Merge<Person>("person", data);

Was this page helpful?