Search
ctrl/
Ask AI
Light
Dark
System

.NET client library for EdgeDB

EdgeDB.Net is the official EdgeDB .NET client, compatable with C#, F# and VB.NET.

EdgeDB version 2.0 and above is required to use EdgeDB.Net.

EdgeDB.Net is distributed between two package managers: NuGet and MyGet; for stable and unstable respectively. To install the latest version, run the following command in your terminal:

At this time, there is no base support for EFCore.

NuGet
MyGet
Copy
$ 
dotnet add package EdgeDB.Net.Driver
Copy
$ 
dotnet add package EdgeDB.Net.Driver --source https://www.myget.org/F/edgedb-net/api/v3/index.json

To start, you will need to setup an EdgeDB project and have an instance created. For more information regarding how to do this, we recommend going through the Quickstart guide.

After you have an instance running, you may now create an EdgeDBClient:

C#
F#
Copy
using EdgeDB.Net;

var client = new EdgeDBClient();
Copy
open EdgeDB

let client = EdgeDBClient()

EdgeDBClient will automatically attempt to resolve your project’s instance. In most circumstances, you won’t need to specify any connection parameters. However, if you do need to, you’ll want to do that by using EdgeDBConnection.Parse() and passing the result into the client’s instance.

Executing a query is simple in the .NET driver. Let’s make and execute a query with the QuerySingleAsync<T> method and printing its result:

C#
F#
Copy
var result = await client.QuerySingleAsync<string>("SELECT \"Hello, World!\"");

Console.WriteLine(result);
Copy
let result =
  client.QuerySingleAsync<string>("SELECT \"Hello, World!\"")
  |> Async.AwaitTask
  |> Async.RunSynchronously

printfn $"{result}"

For more information on how EdgeDB types are mapped to .NET types, refer to the documentation on datatypes.

Cardinality is exposed as different methods in the EdgeDBClient. This means you will need to specify which cardinality you want in your query by using what’s given in the table below:

Cardinality

Method

Result

Many

QueryAsync<T>

IReadOnlyCollection<T?>

At Most One

QuerySingleAsync<T>

T?

One

QueryRequiredSingleAsync<T>

T

Each query method shown takes in T representing the return type.

For object representation, you can either use classes or structs to reflect the names and values within each result.

C#
F#
Copy
public class Person
{
    public string? Name { get; set; }
    public int Age { get; set; }
}

var result = await client.QueryAsync<Person>("SELECT Person { Name, Age }");
Copy
type Person = { Name: string; Age: int }

let result = // Person list
  client.QueryAsync<Person>("SELECT Person { Name, Age }")
  |> Async.AwaitTask
  |> Async.RunSynchronously
  |> List.ofSeq

For more information on how to use classes, refer to the documentation on custom types.

EdgeDB.Net supports Dependency Injection design patterns, allowing you to easily integrate EdgeDB with your existing applications.

C#
F#
Copy
using EdgeDB.Net;
using Microsoft.Extensions.DependencyInjection;

...

services.AddEdgeDB();
Copy
open EdgeDB.Net;
open Microsoft.Extensions.DependencyInjection;

...

services.AddEdgeDB();

You can specify both a EdgeDBConnection and a delegate for configuring the EdgeDBClientConfig, the client will be added as a singleton to your service collection.

Currently, there is no way to create a factory for clients, your service collection may only contain one EdgeDBClient.