• Start

Languages

/

.NET

/

Methods

Upsert

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

Creates or updates a specific record.

Method Syntax

await db.Upsert<T>(data)
ArgumentsDescription
data The document / record data to insert.
cancellationToken The cancellationToken enables graceful cancellation of asynchronous operations.
var person = new Person
{
Id = ("person", "tobie"), // Id is mandatory to apply create or update
Name = "Tobie",
Settings = new Settings
{
Active = true,
Marketing = true,
},
};

// Create a new record when it doesn't exist
var created = await db.Upsert(person);

// Update an existing record when it does exist
var updated = await db.Upsert(person);

Was this page helpful?