The .NET SDK translates datatypes native to SurrealQL into either datatypes native to .NET, or a custom implementation. This document describes all datatypes, and links to their respective documentation.
Datatype | Kind | Documentation | |
---|---|---|---|
String | Native | String | |
Number | Native | Any number type, e.g. Int32 ,Single | |
Float | Native | Any number type, e.g. Int32 ,Single | |
Bool | Native | Boolean | |
Null | Native | null | |
None | Custom | None | |
Array | Native | Any | |
Object | Native | Any | |
Datetime | Native | DateTime orDateOnly | |
Binary | Native | byte[] | |
Uuid | Native | Guid | |
Duration | Native | TimeSpan orTimeOnly | |
Decimal | Native | Decimal | |
Geometry | via Microsoft.Spatial |
| |
Table | Native | String | |
RecordId | Custom | RecordId |
None
The None
type is a custom type that represents the absence of a value.
Signaturepublic readonly struct None { }
None
Constructingvar none = new None(); // Change the value of a record to None var myRecord = new MyRecord(); myRecord.Value = new None();
RecordId
When you receive a RecordId back from SurrealDB, it will always be represented as a RecordId
. The class holds Table
and Id
fields, representing the table name, and a unique identifier for the record on that table.
Signaturepublic class RecordId { public string Table { get; } public T DeserializeId<T>(); // ... The rest is omitted for brevity }
The RecordId
is a non-generic class, allowing you to extract the Id
field by providing the output type via the DeserializeId
method. This can helpful when the RecordId
is used in a generic context, for when you store the Id
as an Object or an Array for example.
For cases where you are aware of the type of the Id
field, you can use the generic version of RecordId
to avoid the need for manual deserialization.
Signature with genericspublic class RecordIdOf<T> : RecordId { public T Id { get; } }
The default type of an Id
in SurrealDB being a string
, you can choose to use the default provided type RecordIdOfString
.
Default RecordIdpublic class RecordIdOfString : RecordIdOf<string> { // The available properties, inherited from `RecordId` and `RecordIdOf<string>` public string Table { get; } public string Id { get; } }
RecordId
Constructing// Table is "person" // Unique identifier on the table is "john" var rid = new RecordId("person", "john"); // Alternatively, a RecordId can be inferred implicitly from a Tuple of 2 elements RecordId rid = ("person", "john"); await client.Select(("person", "john"));
You are not exclusively limited to the string
type for the Id
part. The next section contains examples of how to work with different data types in the Id
field.
The .NET SDK handles serialization and deserialization of the Table
and Id
parts in Record Id. The serialization is done automatically when sending data to the server. However, deserialization may need to be done manually according to the data type of the Id
field. Below are some examples:
Simple record idvar rid = new RecordId("person", "john"); string table = rid.Table; // "person" string id = rid.DeserializeId<string>(); // "john"
Record id with simple data type (other than string)var rid = new RecordId("table", 42); string table = rid.Table; // "table" int id = rid.DeserializeId<int>(); // 42
Record id with complex data typesvar rid = new RecordId("table", new CityId { city: "London" }); var id = rid.DeserializeId<CityId>(); // CityId { city: "London" } var rid = new RecordId("table", ("London", 42)); var id = rid.DeserializeId<(string, int)>(); // ("London", 42)
If you need to send back a Record Id in string format, you can do so with the StringRecordId
class.
We do not implement the parsing of Record Ids in the .NET SDK, as that would mean that we need to be able to parse any SurrealQL value, which comes with a cost. Instead you can send it over as a string with StringRecordId
, allowing the server to handle the parsing.
Signaturepublic class StringRecordId { public string Value { get; } }
StringRecordId
Constructing// Table is "person" // Unique identifier on the table is "john" var rid = new StringRecordId("person:john"); // Alternatively, a StringRecordId can be inferred explicitly from a string var rid = (StringRecordId)"person:john"; await client.Select((StringRecordId)"person:john");