• Start

Concepts

Set parameters

In this section, you will learn how to set parameters in the .NET SDK for SurrealDB.

Within your application, you can define parameters that can be used to store and retrieve data from SurrealDB.
Parameters are used to store data in a structured format, and can be used to store data in a key-value pair format.

Important

Parameters allow you to define global (database-wide) parameters that are available to every client.

Method

Description

db.Set(key, value)

Assigns a value as a parameter for this connection

db.Unset(key)

Removes a parameter for this connection

Assigns a value as a parameter for this connection.

Method Syntax
await db.Set(key, val)

Arguments

Description

key

Specifies the name of the variable.

value

Assigns the value to the variable name.

cancellationToken

The cancellationToken enables graceful cancellation of asynchronous operations.

// Assign the variable on the connection
await db.Set("name", new Name { FirstName = "Tobie",
    LastName = "Morgan Hitchcock" });

// Use the variable in a subsequent query
await db.Query($"CREATE person SET name = $name");

// Use the variable in a subsequent query
await db.Query($"SELECT * FROM person WHERE name.first_name = $name.first_name");


Removes a parameter for this connection.

Method Syntax
await db.Unset(key)

Arguments

Description

key

Specifies the SurrealQL statements.

cancellationToken

The cancellationToken enables graceful cancellation of asynchronous operations.

await db.Unset("name");

Was this page helpful?