ORM Basics Adjusting SQL Data Types
- 04 Oct 2022
- 1 Minute to read
- Print
- DarkLight
ORM Basics Adjusting SQL Data Types
- Updated on 04 Oct 2022
- 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 in a field.
Below is a table displaying the typeof() ORM Field Convertors.
ORM Field Convertor | Decisions Type | Store as SQL Type |
---|---|---|
EnumFieldConverter | Enum | String |
KeyFieldConverter | PK | Primary Key |
StringArrayFieldConverter | String[] | Serialized Text |
TextFieldCoverter | String | nvarchar(max) |
ORMZmlSerializedFieldConverter | XML | XML |
ORMDataPairFieldConverter | DataPair | Serialized Text |
ORMBinaryFieldConverter | Binary | Binary |
ORMWritableFieldConverter | Generic Serialized Object Graph | Binary |
FixedLengthStringFieldConverter | String | varchar(length) |
EncryptedConverter | ANy | Encrypted Binary |
BaseDateTimeConverter | DateTime | DateTime |
BaseDateConverter | Date | DateTime |
TimeFieldConverter | Time | Time |
TimeSpanORMFieldConverter | TimeSpan | Long |
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?