Class ColumnType
A class holding the definition of a sql column type
Inherited Members
Namespace: LemonEdge.Utils.Database
Assembly: LemonEdge.Utils.dll
Syntax
[DataContract]
public sealed class ColumnType
Properties
Collation
Indicates the collation this column should use. Not needed by default the system will provide the database collation
Declaration
public string Collation { get; set; }
Property Value
Type | Description |
---|---|
string |
DefaultSQL
SQL to give this column a default value when upgrading, or creating the column.
For instance when changing a column from nullable to not nullable, this should have a default value
Declaration
public string DefaultSQL { get; }
Property Value
Type | Description |
---|---|
string |
MaxTextSize
If this type is a type of text column this holds the max size. Null is the equivalent of nvarchar(max)
Declaration
public short? MaxTextSize { get; }
Property Value
Type | Description |
---|---|
short? |
Nullable
Whether or not this column is nullable
Declaration
public bool Nullable { get; }
Property Value
Type | Description |
---|---|
bool |
Precision
If this column is a decimal, this holds the precision
Declaration
public Precision Precision { get; }
Property Value
Type | Description |
---|---|
Precision |
Sparse
Indicates if this column should be created as a sparse column
Declaration
public bool Sparse { get; set; }
Property Value
Type | Description |
---|---|
bool |
Type
The sql type of this column
Declaration
public SQLType Type { get; }
Property Value
Type | Description |
---|---|
SQLType |
Methods
Create(SQLType, bool, short?, short?, short?, string, string)
Creates a new column type with settings for all sql types
Declaration
public static ColumnType Create(SQLType type, bool nullable, short? length, short? precision, short? scale, string collation = "", string defaultSQL = "")
Parameters
Type | Name | Description |
---|---|---|
SQLType | type | The sql type of the column to create |
bool | nullable | If the type should be nullable or not |
short? | length | The default length for this column type if it is a text or similar type. If null then it would generate nvarchar(max) or similar |
short? | precision | The number of total digits if this is a decimal type |
short? | scale | The number of decimal places if this is a decimal type |
string | collation | The collation to use for this column if it is a text type |
string | defaultSQL | Any default sql for creating this column |
Returns
Type | Description |
---|---|
ColumnType | A new column type with settings for all sql types |
Create(SQLType, bool, string)
Creates a new ColumnType without any text max settings, or decimal precision settings
Declaration
public static ColumnType Create(SQLType type, bool nullable, string defaultSQL = "")
Parameters
Type | Name | Description |
---|---|---|
SQLType | type | The sql type of this column |
bool | nullable | If the type should be nullable or not |
string | defaultSQL | Any default sql for creating this column |
Returns
Type | Description |
---|---|
ColumnType | A new ColumnType without any text max settings, or decimal precision settings |
Create(Type, bool, string)
Creates a new ColumnType using the default equivalent for the specified .Net Core type
Declaration
public static ColumnType Create(Type type, bool nullable, string defaultSQL)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The .Net Core type to create the equivalent default sql type for |
bool | nullable | If the type should be nullable or not |
string | defaultSQL | Any default sql for creating this column |
Returns
Type | Description |
---|---|
ColumnType | A new ColumnType using the default equivalent for the specified .Net Core type |
CreateWithLength(SQLType, short?, bool, string, string)
Creates a new ColumnType with settings for a string type of column
Declaration
public static ColumnType CreateWithLength(SQLType type, short? length, bool nullable, string collation = "", string defaultSQL = "")
Parameters
Type | Name | Description |
---|---|---|
SQLType | type | The sql type of this column (should be nvarchar, text, varchar, or the like) |
short? | length | The default length for this column type. If null then it would generate nvarchar(max) |
bool | nullable | If the type should be nullable or not |
string | collation | The collation to use for this column |
string | defaultSQL | Any default sql for creating this column |
Returns
Type | Description |
---|---|
ColumnType | A new ColumnType with settings for a string type of column |
CreateWithPrecision(SQLType, Precision, bool, string)
Creates a new ColumnType with settings for decimal precision
Declaration
public static ColumnType CreateWithPrecision(SQLType type, Precision precision, bool nullable, string defaultSQL = "")
Parameters
Type | Name | Description |
---|---|---|
SQLType | type | The sql type of this column (should be decimal or the like) |
Precision | precision | The precision for this decimal column type |
bool | nullable | If the type should be nullable or not |
string | defaultSQL | Any default sql for creating this column |
Returns
Type | Description |
---|---|
ColumnType | A new ColumnType with settings for decimal precision |
EquivelantDotNetType(bool)
Returns the equivalent .Net Core type for this column
Declaration
public Type EquivelantDotNetType(bool includeNullable)
Parameters
Type | Name | Description |
---|---|---|
bool | includeNullable | Indicates if the type returned should include if this column is nullable or not |
Returns
Type | Description |
---|---|
Type | The equivalent .Net Core type for this column |
From(ColumnType, bool?)
Declaration
public static ColumnType From(ColumnType original, bool? nullable = null)
Parameters
Type | Name | Description |
---|---|---|
ColumnType | original | |
bool? | nullable |
Returns
Type | Description |
---|---|
ColumnType |
FromType(Type)
Creates a default equivalent ColumnType for the specified .Net Core type. For instance would return NVarchar(max) for typeof(string)
Declaration
public static ColumnType FromType(Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The .Net Core type to return an equivalent default ColumnType for |
Returns
Type | Description |
---|---|
ColumnType | A default equivalent ColumnType for the specified .Net Core type. For instance would return NVarchar(max) for typeof(string) |
ToString()
Returns the sql equivalent of this column, excluding nullable and collation info - so just the equivalent of the type like varchar(max)
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | The sql equivalent of this column, excluding nullable and collation info - so just the equivalent of the type like varchar(max) |
Overrides
ToString(bool, bool, string)
Returns the sql equivalent of this column including attributes required for creating the column such as nullable and collation like varchar(max) collate xxx null
Declaration
public string ToString(bool includeNullable, bool includeCollation, string collationOverride = "")
Parameters
Type | Name | Description |
---|---|---|
bool | includeNullable | |
bool | includeCollation | |
string | collationOverride |
Returns
Type | Description |
---|---|
string | The sql equivalent of this column including attributes required for creating the column such as nullable and collation like varchar(max) collate xxx null |