.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.
Installing
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.
$
dotnet add package EdgeDB.Net.Driver
$
dotnet add package EdgeDB.Net.Driver --source https://www.myget.org/F/edgedb-net/api/v3/index.json
Quickstart
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
:
using EdgeDB.Net;
var client = new EdgeDBClient();
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 queries
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:
var result = await client.QuerySingleAsync<string>("SELECT \"Hello, World!\"");
Console.WriteLine(result);
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 and return types
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 |
|
|
At Most One |
|
|
One |
|
|
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.
public class Person
{
public string? Name { get; set; }
public int Age { get; set; }
}
var result = await client.QueryAsync<Person>("SELECT Person { Name, Age }");
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.
Dependency Injection (DI)
EdgeDB.Net supports Dependency Injection design patterns, allowing you to easily integrate EdgeDB with your existing applications.
using EdgeDB.Net;
using Microsoft.Extensions.DependencyInjection;
...
services.AddEdgeDB();
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
.