Class DataTableDef
Database table definition
public class DataTableDef
- Inheritance
-
DataTableDef
- Inherited Members
- Extension Methods
Constructors
DataTableDef()
Constructor
public DataTableDef()
Properties
Fields
Fields
public List<DataFieldDef> Fields { get; set; }
Property Value
Id
A GUID string.
public string Id { get; set; }
Property Value
IdentifierMaxLength
Max length for all identifier names such as Table, Field and Constraint names.
public static int IdentifierMaxLength { get; set; }
Property Value
Name
A name unique among all instances of this type
public string Name { get; set; }
Property Value
Title
Gets the Title of this instance, used for display purposes.
NOTE: The setter is fake. Do NOT use it.
public string Title { get; set; }
Property Value
TitleKey
Gets or sets a resource Key used in returning a localized version of Title
public string TitleKey { get; set; }
Property Value
UniqueConstraints
For multi-field unique constraints.
Use it when a unique constraint is required on more than a single field adding a proper string, e.g. Field1, Field2
public List<UniqueConstraintDef> UniqueConstraints { get; set; }
Property Value
Methods
AddBlob(string, bool, string)
Creates, adds and returns a field of a certain type.
public DataFieldDef AddBlob(string FieldName, bool Required = false, string TitleKey = null)
Parameters
Returns
AddBoolean(string, bool, string, string)
Creates, adds and returns a field of a certain type.
public DataFieldDef AddBoolean(string FieldName, bool Required = false, string TitleKey = null, string DefaultExpression = null)
Parameters
Returns
AddDate(string, bool, string, string)
Creates, adds and returns a field of a certain type.
public DataFieldDef AddDate(string FieldName, bool Required = false, string TitleKey = null, string DefaultExpression = null)
Parameters
Returns
AddDateTime(string, bool, string, string)
Creates, adds and returns a field of a certain type.
public DataFieldDef AddDateTime(string FieldName, bool Required = false, string TitleKey = null, string DefaultExpression = null)
Parameters
Returns
AddDecimal(string, string, bool, string, string)
Creates, adds and returns a field of a certain type.
NOTE: The decimal part should be given without parentheses.
public DataFieldDef AddDecimal(string FieldName, string DecimalPart = "18, 4", bool Required = false, string TitleKey = null, string DefaultExpression = null)
Parameters
Returns
AddField(string, DataFieldType, bool, string, string)
Creates, adds and returns a field.
public DataFieldDef AddField(string FieldName, DataFieldType DataType, bool Required = false, string TitleKey = null, string DefaultExpression = null)
Parameters
FieldNamestringDataTypeDataFieldTypeRequiredboolTitleKeystringDefaultExpressionstring
Returns
AddFloat(string, bool, string, string)
Creates, adds and returns a field of a certain type.
public DataFieldDef AddFloat(string FieldName, bool Required = false, string TitleKey = null, string DefaultExpression = null)
Parameters
Returns
AddId(string, int, string)
Creates, adds and returns a primary key field.
NOTE: This version adds a data-type according to GuidOids flag.
public DataFieldDef AddId(string FieldName = "Id", int Length = 40, string TitleKey = null)
Parameters
Returns
AddId(string, DataFieldType, int, string)
Creates, adds and returns a primary key field of a defined type.
NOTE: String and Integer are the only supported types.
public DataFieldDef AddId(string FieldName, DataFieldType DataType, int Length, string TitleKey = null)
Parameters
FieldNamestringDataTypeDataFieldTypeLengthintTitleKeystring
Returns
AddInteger(string, bool, string, string)
Creates, adds and returns a field of a certain type.
public DataFieldDef AddInteger(string FieldName, bool Required = false, string TitleKey = null, string DefaultExpression = null)
Parameters
Returns
AddIntegerId(string, string)
Creates, adds and returns an integer primary key field.
public DataFieldDef AddIntegerId(string FieldName = "Id", string TitleKey = null)
Parameters
Returns
AddString(string, int, bool, string, string)
Creates, adds and returns a string (nvarchar) field.
public DataFieldDef AddString(string FieldName, int Length = 96, bool Required = false, string TitleKey = null, string DefaultExpression = null)
Parameters
Returns
AddStringId(string, int, string)
Creates, adds and returns a string primary key field.
public DataFieldDef AddStringId(string FieldName = "Id", int Length = 40, string TitleKey = null)
Parameters
Returns
AddTextBlob(string, bool, string)
Creates, adds and returns a field of a certain type.
public DataFieldDef AddTextBlob(string FieldName, bool Required = false, string TitleKey = null)
Parameters
Returns
AddUniqueConstraint(string, string)
Creates, adds and returns a unique constraint.
Used when a unique constraint is required on more than a single field, by adding a proper string, e.g. Field1, Field2
public UniqueConstraintDef AddUniqueConstraint(string FieldNames, string ConstraintName = "")
Parameters
Returns
Check()
Throws an exception if this instance is not a valid one.
public void Check()
CheckIsValidDatabaseObjectIdentifier(string)
Validates a specified database object identifier and throws an exception if it is invalid.
public static void CheckIsValidDatabaseObjectIdentifier(string Name)
Parameters
Namestring
CreateOrAlterTable(DataTableDef, DataTableDef)
Creates or alters a specified table in the default database connection.
Use the overload with a DbConnectionInfo parameter to target a specific database connection.
public static void CreateOrAlterTable(DataTableDef NewTableDef, DataTableDef OldTableDef = null)
Parameters
NewTableDefDataTableDefOldTableDefDataTableDef
CreateOrAlterTable(DbConnectionInfo, DataTableDef, DataTableDef)
Creates or alters a specified table in the specified database connection.
When only the new definition is passed a new database table is created.
When both the new and the old definitions are passed, the function compares their fields and adds, drops or alters columns accordingly.
public static void CreateOrAlterTable(DbConnectionInfo ConnectionInfo, DataTableDef NewTableDef, DataTableDef OldTableDef = null)
Parameters
ConnectionInfoDbConnectionInfoNewTableDefDataTableDefOldTableDefDataTableDef
EnsureIdentifierValidLength(string)
Forces a specified identifier name, such as Table or Field name, to have a valid max length.
public static string EnsureIdentifierValidLength(string IdentifierName)
Parameters
IdentifierNamestring
Returns
GetDefText()
Returns the table definition text.
WARNING: The returned text must be passed through ReplaceDataTypePlaceholders(string) method, for the final result.
public string GetDefText()
Returns
SplitForeignKey(string, out string, out string)
Splits a specified foreign key string of the form
TableName.ColumnName
and returns its two parts: ForeignTableName and ForeignColumnName
public static void SplitForeignKey(string ForeignKey, out string ForeignTableName, out string ForeignColumnName)
Parameters
ToString()
Returns a string representation of this instance.
public override string ToString()