ORM Basics Adjusting SQL Data Types
  • 07 Nov 2020
  • 1 Minute to read
  • Dark
    Light
  This documentation version is deprecated, please click here for the latest version.

ORM Basics Adjusting SQL Data Types

  • Dark
    Light

Article summary

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 ConvertorsDecisions TypeStore as SQL Type
EnumFieldConverterEnumString
                                  [ORMField(“Optional_FieldName”, typeof(EnumFieldConverter))]
KeyFieldConverterPKPrimary Key
StringArrayFieldConverterString[]Serialized Text
TextFieldConverterStringNVARCHAR(MAX)
ORMXmlSerializedFieldConverterXMLXML
ORMDataPairFieldConverterDataPairSerialized Text
ORMBinaryFieldConverterBinaryBinary
ORMWritableFieldConverterGeneric Serialized Object GraphBinary
FixedLengthStringFieldConverterStringVARCHAR(length)
                                   [ORMField(“Optional_FieldName”, length, typeof( FixedLengthStringFieldConverter ))]
EncryptedConverterAnyEncrypted Binary
BaseDateTimeConverterDateTimeDateTime
BaseDateConverterDateDateTime
TimeFieldConverterTimeTime
TimeSpanORMFieldConverterTimeSpanLong


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?