ORM Basics Adjusting SQL Data Types
  • 04 Oct 2022
  • 1 Minute to read
  • Dark
    Light

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 in a field. 

Below is a table displaying the typeof() ORM Field Convertors.

ORM Field ConvertorDecisions TypeStore as SQL Type
EnumFieldConverterEnumString
KeyFieldConverterPKPrimary Key
StringArrayFieldConverterString[]Serialized Text
TextFieldCoverterStringnvarchar(max)
ORMZmlSerializedFieldConverterXMLXML
ORMDataPairFieldConverterDataPairSerialized Text
ORMBinaryFieldConverterBinaryBinary
ORMWritableFieldConverterGeneric Serialized Object GraphBinary
FixedLengthStringFieldConverterStringvarchar(length)
EncryptedConverterANyEncrypted Binary
BaseDateTimeConverterDateTimeDateTime
BaseDateConverterDateDateTime
TimeFieldConverterTimeTime
TimeSpanORMFieldConverterTimeSpanLong

Example

The code snippet below demonstrates how to override a long text field. This field will become a nvarchar(max) field in SQL.

[ORMField(typeof(TextFieldConverter))]
[DataMember]
[WritableValue]
public string Description { get; set; }

Below 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?