All data types assignable via the field editor or used by form components must be explicitly registered. The system uses the metadata provided during registration to:
The following table highlights important types registered by default:
Field editor name | C# data type | Database representation | Notes |
|---|---|---|---|
Boolean (Yes/No) | bool | bit (opens in a new tab) | |
Binary | byte[] | varbinary(max) (opens in a new tab) | |
Integer number | int | int (opens in a new tab) | |
Long integer number | long | bigint (opens in a new tab) | |
Floating-point number (Double precision) | double | float (opens in a new tab) | |
Decimal number | decimal | decimal (opens in a new tab) | |
Date | DateTime | date (opens in a new tab) | |
Date and time | DateTime | datetime2 (opens in a new tab) | |
Time interval | TimeSpan | time (opens in a new tab) | |
Text | string | nvarchar (opens in a new tab) | Database field length configurable when creating or editing fields (up to the database maximum). |
Long text | string | nvarchar(max) (opens in a new tab) | |
Unique identifier (GUID) | Guid | uniqueidentifier (opens in a new tab) |
The default set of data types can be extended using the DataTypeManager class, which allows you to register additional data types into the system via the RegisterDataTypes(params DataType[]) method. Data type registrations must be done during application startup.
The DataType<T> class provides multiple constructors suitable depending on the complexity of the type being registered.
For primitive types and simple objects that can be directly serialized to the database, use
DataType<T>(string sqlType, string fieldType, string schemaType, Func<object, T, CultureInfo, T> conversionFunc)where:
IDataContainer.For composite types, use
DataType<T>(string sqlType, string fieldType, string schemaType, Func<object, T, CultureInfo, T> conversionFunc, Func<T, object, CultureInfo, object> dbConversionFunc, IDataTypeTextSerializer textSerializer)where:
xs:string, xs:integer, etc.) used for XML serialization into IDataContainer. For composite types, this is commonly set to xs:string, as you're often storing a serialized object (e.g., as a JSON string).For example, the composite type MyCompositeType:
public class MyCompositeType
{
public int Identifier { get; set; }
public string Name { get; set; }
}would use the following registration:
// Called on application startup
DataTypeManager.RegisterDataTypes(
new DataType<MyCompositeType>("nvarchar(max)", "mydatatype", "xs:string",
MyCompositeTypeHelper.ConvertToSystemRepresentation,
MyCompositeTypeHelper.ConvertToDbRepresentation,
new DefaultDataTypeTextSerializer("mydatatype"))
{
// Data type configuration, see the 'Data type configuration' section for details
}
);
public static class MyCompositeTypeHelper
{
public static object ConvertToDbRepresentation(MyCompositeType value, object defaultValue, CultureInfo culture)
{
if (value == null)
{
return defaultValue;
}
try
{
return JsonSerializer.Serialize(value);
}
catch (Exception e)
{
throw new InvalidOperationException("An error occurred when serializing the data type, see the inner exception for details", e);
}
}
public static MyCompositeType ConvertToSystemRepresentation(object value, MyCompositeType defaultValue, CultureInfo culture)
{
if (value == null)
{
return defaultValue;
}
// We know the value is stored in the database as a JSON string
var stringValue = value as string;
if (string.IsNullOrEmpty(stringValue))
{
return defaultValue;
}
try
{
return JsonSerializer.Deserialize<MyCompositeType>(stringValue);
}
catch (Exception e)
{
throw new InvalidOperationException("An error occurred when deserializing the data type, see the inner exception for details", e);
}
}
}The data type is now registered and can be assigned to object fields via the field editor. Note that to edit fields based on this data type, you also need to develop corresponding form components.
During data type registration, you can also configure the following properties that control the behavior of the system when working with the data type in code generators, the field editor, and database queries.
Field editor
Code generators
String.EmptyGeneral
System.Data.SqlDbType used when generating database queries. Set to the same type as the data type's sqlType parameter.