Table of Contents

Class DataTableDef

Namespace
Tripous.Data
Assembly
Tripous.Data.dll

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

List<DataFieldDef>

Id

A GUID string.

public string Id { get; set; }

Property Value

string

IdentifierMaxLength

Max length for all identifier names such as Table, Field and Constraint names.

public static int IdentifierMaxLength { get; set; }

Property Value

int

Name

A name unique among all instances of this type

public string Name { get; set; }

Property Value

string

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

string

TitleKey

Gets or sets a resource Key used in returning a localized version of Title

public string TitleKey { get; set; }

Property Value

string

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

List<UniqueConstraintDef>

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

FieldName string
Required bool
TitleKey string

Returns

DataFieldDef

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

FieldName string
Required bool
TitleKey string
DefaultExpression string

Returns

DataFieldDef

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

FieldName string
Required bool
TitleKey string
DefaultExpression string

Returns

DataFieldDef

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

FieldName string
Required bool
TitleKey string
DefaultExpression string

Returns

DataFieldDef

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

FieldName string
DecimalPart string
Required bool
TitleKey string
DefaultExpression string

Returns

DataFieldDef

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

FieldName string
DataType DataFieldType
Required bool
TitleKey string
DefaultExpression string

Returns

DataFieldDef

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

FieldName string
Required bool
TitleKey string
DefaultExpression string

Returns

DataFieldDef

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

FieldName string
Length int
TitleKey string

Returns

DataFieldDef

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

FieldName string
DataType DataFieldType
Length int
TitleKey string

Returns

DataFieldDef

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

FieldName string
Required bool
TitleKey string
DefaultExpression string

Returns

DataFieldDef

AddIntegerId(string, string)

Creates, adds and returns an integer primary key field.

public DataFieldDef AddIntegerId(string FieldName = "Id", string TitleKey = null)

Parameters

FieldName string
TitleKey string

Returns

DataFieldDef

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

FieldName string
Length int
Required bool
TitleKey string
DefaultExpression string

Returns

DataFieldDef

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

FieldName string
Length int
TitleKey string

Returns

DataFieldDef

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

FieldName string
Required bool
TitleKey string

Returns

DataFieldDef

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

FieldNames string
ConstraintName string

Returns

UniqueConstraintDef

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

Name string

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

NewTableDef DataTableDef
OldTableDef DataTableDef

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

ConnectionInfo DbConnectionInfo
NewTableDef DataTableDef
OldTableDef DataTableDef

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

IdentifierName string

Returns

string

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

string

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

ForeignKey string
ForeignTableName string
ForeignColumnName string

ToString()

Returns a string representation of this instance.

public override string ToString()

Returns

string