ORM Basics Adjusting SQL Data Types
- 07 Nov 2020
- 1 Minute to read
- Print
- DarkLight
This documentation version is deprecated, please click here for the latest version.
ORM Basics Adjusting SQL Data Types
- Updated on 07 Nov 2020
- 1 Minute to read
- Print
- DarkLight
Article summary
Did you find this summary helpful?
Thank you for your feedback
Overview
Using overrides to the ORMField attribute, developers can set what database type to store a field.
Below is a table displaying Type of ORM Field Convertors.
ORM Field Convertors | Decisions Type | Store as SQL Type |
---|---|---|
EnumFieldConverter | Enum | String |
[ORMField(“Optional_FieldName”, typeof(EnumFieldConverter))] | ||
KeyFieldConverter | PK | Primary Key |
StringArrayFieldConverter | String[] | Serialized Text |
TextFieldConverter | String | NVARCHAR(MAX) |
ORMXmlSerializedFieldConverter | XML | XML |
ORMDataPairFieldConverter | DataPair | Serialized Text |
ORMBinaryFieldConverter | Binary | Binary |
ORMWritableFieldConverter | Generic Serialized Object Graph | Binary |
FixedLengthStringFieldConverter | String | VARCHAR(length) |
[ORMField(“Optional_FieldName”, length, typeof( FixedLengthStringFieldConverter ))] | ||
EncryptedConverter | Any | Encrypted Binary |
BaseDateTimeConverter | DateTime | DateTime |
BaseDateConverter | Date | DateTime |
TimeFieldConverter | Time | Time |
TimeSpanORMFieldConverter | TimeSpan | Long |
Example
Here is an example showing how to override for a long text field. This field will become a nvarchar(max) field in SQL.
[ORMField(typeof(TextFieldConverter))]
[DataMember]
[WritableValue]
public string Description { get; set; }
Here is an example showing how to limit the text length of a field. This field will become a nvarchar(15) field in SQL.
[ORMField("phone_number", 15, typeof(FixedLengthStringFieldConverter))]
[DataMember]
[WritableValue]
public string PhoneNumber { get; set; }
Was this article helpful?