Data Types
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.
Data Types overview
| 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](#none)
|
| Array | Native |
Any IEnumerable representation
|
| Object | Native |
Any Object representation
|
| Datetime | Native |
DateTime
or
DateOnly
|
| Binary | Native |
byte[]
|
| Uuid | Native |
Guid
|
| Duration | Native |
TimeSpan
or
TimeOnly
|
| Decimal | Native |
Decimal
|
| Geometry | via Microsoft.Spatial |
Geometry or Geography representations
|
| Table | Native |
String
|
| RecordId | Custom |
[RecordId](#recordid)
|
None
The None type is a custom type that represents the absence of a value.
Working with 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.
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.
The default type of an Id in SurrealDB being a string, you can choose to use the default provided type RecordIdOfString.
Working with RecordId
The simplest and most common way to construct a RecordId is with a tuple (table, id).
This tuple is implicitly converted into a RecordId object.
You can use it with all SDK methods:
You are not exclusively limited to the string type for the Id part. Several overloads exist for different id types:
Extracting data
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:
Send back string
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.
Working with a StringRecordId
Working with RecordIdOfString
For string-based identifiers, you can also use the specialized type RecordIdOfString:
Working with RecordIdOf<T>
For complex or structured identifiers, use the generic type RecordIdOf\<T\>:
This enables strongly-typed IDs that map directly to your domain objects.
Inheriting from Record
If your model class inherits from Record, it will automatically include an Id property of type RecordId.
Using Data Annotations
The SDK supports attributes for serialization and deserialization.
CBOR serialization
Use CborProperty to map C# properties to SurrealDB fields:
RecordIdJsonConverter
Use RecordIdJsonConverter to indicate that a property should be serialized as a RecordId reference to another table:
Combining attributes
You can combine both attributes on the same property: