Columns are defined by supplying necessary type information in the attribute.
// Max Length String
[Column()] public string my_col;
// Fixed length String
[Column(Length = 10)] public string my_col;
// Fixed length String + Not Nullable
[Column(Length = 10, DefaultValue = "")] public string my_col;
// Numerics
[Column()] public short my_col;
[Column()] public int my_col;
[Column()] public long my_col;
[Column()] public float my_col;
[Column()] public double my_col;
[Column()] public decimal my_col;
[Column(Length = 20, Scale = 2)] public decimal my_col;
// Boolean
public bool; my_col;
// Binary
public byte[] my_col;
// Time
public System.TimeSpan my_col;
[Column()] public System.TimeSpan my_col;
// Date + Time
[Column()] public System.DateTime my_col;
// Only Date
[Column(OnlyDate = true)] public System.DateTime my_col;
// Attributes are defined at once to use as a reference...
public enum Ref {
[Column("year", Length = 4, DefaultValue = 2000, MinValue = 1900, MaxValue = 2100)] year,
[Column("note", Length = 100)] note,
[Column("id", Length = 5)] id,
[Column(DateFormat:=ColumnDateFormat.OnlyDate)] only_date,
...
}
// usage
public class my_table : Odb.Table.Base {
[Column( Ref.year )] public int my_col;
}
// extends the column's length to 5
[Column( Ref.year, Ref.id )] public int my_col;
cn.Provider().ToDbTypeName(table.field);
//-- MsSql = numeric(4, 0)
//-- MySql = DECIMAL(4, 0)
//-- MariaDB = DECIMAL(4, 0)
//-- Oracle = NUMBER(4, 0)
//-- PostgreSql = NUMERIC(4, 0)
//-- SQLite = NUMERIC(4, 0)
It is the name of the column.
is used for string columns and also is the Precision that represents the total number of digits allowed for numeric columns.
| DbType | Byte Size | Accept As |
|---|---|---|
| tinyint | 3 | Length=3, Scale=0 |
| smallint | 5 | Length=5, Scale=0 |
| int | 9 | Length=10, Scale=0 |
| bigint | 9 | Length=19, Scale=0 |
represents the number of decimal places to right of the decimal point.
allows a unique number to be generated automatically when a new record is inserted into a table.
It is the description of the column.
It is determined automatically. If the type is nullable (such as int?, string etc.) and also DefaultValue is not specified then TRUE is accepted. otherwise FALSE is accepted.
It is the min value of the column for checking constraint.
It is the max value of the column for checking constraint.
It is the default value of the column.