Table of Contents

Class TableDef

Namespace
Tripous.Data
Assembly
Tripous.Data.dll

A table definition

public class TableDef : BaseDef, IDef, IJsonLoadable, INotifyPropertyChanged
Inheritance
TableDef
Implements
Inherited Members
Extension Methods

Constructors

TableDef()

Constructor

public TableDef()

TableDef(ModuleDef)

Constructor

public TableDef(ModuleDef ModuleDef)

Parameters

ModuleDef ModuleDef

Fields

ITEM

Constant

public const string ITEM = "_ITEM_"

Field Value

string

LINES

Constant

public const string LINES = "_LINES_"

Field Value

string

SUBLINES

Constant

public const string SUBLINES = "_SUBLINES_"

Field Value

string

Properties

Alias

An alias of this table

public string Alias { get; set; }

Property Value

string

DetailField

The detail key field. A field that belongs to this table and matches the primary key field of the master table.

It is used when this table is a detail table in a master-detail relation.

public string DetailField { get; set; }

Property Value

string

Details

The detail tables of this table.

public DefList<TableDef> Details { get; set; }

Property Value

DefList<TableDef>

FieldGroups

Preferred field group display order.

public List<string> FieldGroups { get; set; }

Property Value

List<string>

Fields

The fields of this table

public DefList<FieldDef> Fields { get; set; }

Property Value

DefList<FieldDef>

HasDetails

True when this table has details

[JsonIgnore]
public bool HasDetails { get; }

Property Value

bool

HasJoins

True when this table has joins

[JsonIgnore]
public bool HasJoins { get; }

Property Value

bool

HasStocks

True when this table has stocks

[JsonIgnore]
public bool HasStocks { get; }

Property Value

bool

IsDetail

When true then this is a detail table, e.g. a TradeLines under a Trade table.

public bool IsDetail { get; set; }

Property Value

bool

IsJoin

True when this is a table joined to another table.

[JsonIgnore]
public bool IsJoin { get; }

Property Value

bool

IsOneToOne

Sometimes there is an one-to-one relationship between the top table, i.e. Table and one or more details, but single-row tables.

For example: Trade and StoreTrade and FinTrade, where Trade is the top table and StoreTrade and FinTrade are IsOneToOne table.

public bool IsOneToOne { get; set; }

Property Value

bool

IsUiVisible

When false then the table is not visible in the UI.

Useful with IsOneToOne details, for example when a Trade table has one-to-one details tables such as the StoreTrade and FinTrade.

It is also useful with multi-row detail tables when the table must remain hidden, without a grid in the UI.

public bool IsUiVisible { get; set; }

Property Value

bool

Joins

The list of join tables.

public DefList<TableDef> Joins { get; set; }

Property Value

DefList<TableDef>

KeyField

Gets or sets the name of the primary key field of this table.

public string KeyField { get; set; }

Property Value

string

Master

The master table when this is a detail table.

[JsonIgnore]
public TableDef Master { get; set; }

Property Value

TableDef

MasterField

Gets or sets the field name of a field belonging to a master table.

Used when this table is a detail table in a master-detail relation or when this is a join table.

public string MasterField { get; set; }

Property Value

string

ModuleDef

The master definition this instance belongs to.

[JsonIgnore]
public ModuleDef ModuleDef { get; set; }

Property Value

ModuleDef

Owner

When this is a join table, the owner is the table that joins this table.

[JsonIgnore]
public TableDef Owner { get; set; }

Property Value

TableDef

Sqls

The SQL statements associated with this table.

public TableSqls Sqls { get; set; }

Property Value

TableSqls

Stocks

The main table (Item) is selected as

select * from TABLE_NAME where ID = :ID

If the table contains foreign keys, for instance CUSTOMER_ID etc, then those foreign tables are NOT joined. The programmer who designs the UI just creates a Locator where needed.

But there is always the need to have data from those foreign tables in many situations, i.e. in reports.

StockTables are used for that. StockTables are selected each time after the select of the main table (Item)

public DefList<SelectDef> Stocks { get; set; }

Property Value

DefList<SelectDef>

Methods

Add(string, int, string, string, FieldFlags)

Adds and returns a string field.

public FieldDef Add(string Name, int MaxLength, string Group = null, string TitleKey = "", FieldFlags Flags = FieldFlags.None)

Parameters

Name string
MaxLength int
Group string
TitleKey string
Flags FieldFlags

Returns

FieldDef

AddBlob(string, string, string, FieldFlags)

Adds and returns a blob field.

public FieldDef AddBlob(string Name, string Group = null, string TitleKey = "", FieldFlags Flags = FieldFlags.None)

Parameters

Name string
Group string
TitleKey string
Flags FieldFlags

Returns

FieldDef

AddBoolean(string, string, string, FieldFlags)

Adds and returns an integer-boolean field.

public FieldDef AddBoolean(string Name, string Group = null, string TitleKey = "", FieldFlags Flags = FieldFlags.None)

Parameters

Name string
Group string
TitleKey string
Flags FieldFlags

Returns

FieldDef

AddDate(string, string, string, FieldFlags)

Adds and returns an date field.

public FieldDef AddDate(string Name, string Group = null, string TitleKey = "", FieldFlags Flags = FieldFlags.None)

Parameters

Name string
Group string
TitleKey string
Flags FieldFlags

Returns

FieldDef

AddDateTime(string, string, string, FieldFlags)

Adds and returns an date-time field.

public FieldDef AddDateTime(string Name, string Group = null, string TitleKey = "", FieldFlags Flags = FieldFlags.None)

Parameters

Name string
Group string
TitleKey string
Flags FieldFlags

Returns

FieldDef

AddDecimal(string, string, int, string, FieldFlags)

Adds and returns an decimal field.

public FieldDef AddDecimal(string Name, string Group = null, int Decimals = 4, string TitleKey = "", FieldFlags Flags = FieldFlags.None)

Parameters

Name string
Group string
Decimals int
TitleKey string
Flags FieldFlags

Returns

FieldDef

AddDetail(string, string, string)

Adds a detail table to this table.

public TableDef AddDetail(string DetailTableName, string MasterField, string DetailField)

Parameters

DetailTableName string
MasterField string
DetailField string

Returns

TableDef

AddDouble(string, string, int, string, FieldFlags)

Adds and returns an double field.

public FieldDef AddDouble(string Name, string Group = null, int Decimals = 4, string TitleKey = "", FieldFlags Flags = FieldFlags.None)

Parameters

Name string
Group string
Decimals int
TitleKey string
Flags FieldFlags

Returns

FieldDef

AddEnumLookupId(string, string, Type, string, bool, string, FieldFlags)

Adds a fields, such as AggregateId which needs a LookupDef of an enum type, such as the AggregateType, in order to be displayed correctly in the Ui.

NOTE: This method creates and registers the required LookupDef to the registry.

public FieldDef AddEnumLookupId(string Name, string LookupSource, Type EnumType, string Group = null, bool UseNullItem = false, string TitleKey = null, FieldFlags Flags = FieldFlags.None)

Parameters

Name string
LookupSource string
EnumType Type
Group string
UseNullItem bool
TitleKey string
Flags FieldFlags

Returns

FieldDef

AddField(string, DataFieldType, string, string, string, int, int, string, string, FieldFlags)

Adds and returns a field.

public FieldDef AddField(string Name, DataFieldType DataType, string Group = null, string TitleKey = null, string Alias = null, int MaxLength = -1, int Decimals = -1, string LookupSource = null, string Locator = null, FieldFlags Flags = FieldFlags.None)

Parameters

Name string
DataType DataFieldType
Group string
TitleKey string
Alias string
MaxLength int
Decimals int
LookupSource string
Locator string
Flags FieldFlags

Returns

FieldDef

AddId(string, DataFieldType, FieldFlags, int)

Adds and returns an Id field.

public FieldDef AddId(string Name, DataFieldType DataType, FieldFlags Flags = FieldFlags.Hidden | FieldFlags.Required, int MaxLength = 40)

Parameters

Name string
DataType DataFieldType
Flags FieldFlags
MaxLength int

Returns

FieldDef

AddId(string, FieldFlags)

Adds and returns an Id field based on settings on OidDataType and OidSize.

public FieldDef AddId(string Name = "Id", FieldFlags Flags = FieldFlags.Hidden | FieldFlags.Required)

Parameters

Name string
Flags FieldFlags

Returns

FieldDef

AddInteger(string, string, string, FieldFlags)

Adds and returns an integer field.

public FieldDef AddInteger(string Name, string Group = null, string TitleKey = "", FieldFlags Flags = FieldFlags.None)

Parameters

Name string
Group string
TitleKey string
Flags FieldFlags

Returns

FieldDef

AddIntegerId(string, FieldFlags)

Adds and returns an integer Id field

public FieldDef AddIntegerId(string Name = "Id", FieldFlags Flags = FieldFlags.Hidden | FieldFlags.Required)

Parameters

Name string
Flags FieldFlags

Returns

FieldDef

AddIntegerLookupId(string, string, string, string, FieldFlags)

Adds a fields, such as CountryId which needs a LookupDef in order to be displayed correctly in the Ui.

The LookupDef should be registered in the registry.

public FieldDef AddIntegerLookupId(string Name, string LookupSource, string Group = null, string TitleKey = null, FieldFlags Flags = FieldFlags.None)

Parameters

Name string
LookupSource string
Group string
TitleKey string
Flags FieldFlags

Returns

FieldDef

AddJoin(string, string, string, string)

Adds a table join in this table and returns the joined table.

If this is CUSTOMER table then the COUNTRY table can be joined as

TableName: COUNTRY

Alias: empty string or null or an alias

OwnKeyField: COUNTRY_ID

The above settings produce the following:

left join COUNTRY on COUNTRY.ID = CUSTOMER.COUNTRY_ID

public TableDef AddJoin(string OwnKeyField, string ForeignTable, string ForeignAlias = "", string ForeignPrimaryKey = "Id")

Parameters

OwnKeyField string

A field that belongs to this table. Is used in the join SQL statement

ForeignTable string

The name of the table to join, e.g. COUNTRY to CUSTOMER

ForeignAlias string

The alias of the table to join, e.g. co

ForeignPrimaryKey string

The primary key field name of the table to join, e.g. Id

Returns

TableDef

AddJoin(string, string, string, string, string)

Adds a table join in this table and returns the joined table.

If this is CUSTOMER table then the COUNTRY table can be joined as

TableName: COUNTRY

Alias: empty string or null or an alias

OwnKeyField: COUNTRY_ID

The above settings produce the following:

left join COUNTRY on COUNTRY.ID = CUSTOMER.COUNTRY_ID

public TableDef AddJoin(string OwnKeyField, string Locator, string ForeignTable, string ForeignAlias = "", string ForeignPrimaryKey = "Id")

Parameters

OwnKeyField string

A field that belongs to this table. Is used in the join SQL statement

Locator string

The locator name to be used in the owner key field.

ForeignTable string

The name of the table to join, e.g. COUNTRY to CUSTOMER

ForeignAlias string

The alias of the table to join, e.g. co

ForeignPrimaryKey string

The primary key field name of the table to join, e.g. Id

Returns

TableDef

AddLookupId(string, DataFieldType, string, string, string, FieldFlags)

Adds a fields, such as CountryId which needs a LookupDef in order to be displayed correctly in the Ui.

The LookupDef should be registered in the registry.

public FieldDef AddLookupId(string Name, DataFieldType DataType, string LookupSource, string Group = null, string TitleKey = null, FieldFlags Flags = FieldFlags.None)

Parameters

Name string
DataType DataFieldType
LookupSource string
Group string
TitleKey string
Flags FieldFlags

Returns

FieldDef

AddString(string, int, string, string, FieldFlags)

Adds and returns a string field.

public FieldDef AddString(string Name, int MaxLength = 96, string Group = null, string TitleKey = "", FieldFlags Flags = FieldFlags.None)

Parameters

Name string
MaxLength int
Group string
TitleKey string
Flags FieldFlags

Returns

FieldDef

AddStringId(string, FieldFlags, int)

Adds and returns a string Id field

public FieldDef AddStringId(string Name = "Id", FieldFlags Flags = FieldFlags.Hidden | FieldFlags.Required, int MaxLength = 40)

Parameters

Name string
Flags FieldFlags
MaxLength int

Returns

FieldDef

AddStringLookupId(string, string, string, string, FieldFlags)

Adds a fields, such as CountryId which needs a LookupDef in order to be displayed correctly in the Ui.

The LookupDef should be registered in the registry.

public FieldDef AddStringLookupId(string Name, string LookupSource, string Group = null, string TitleKey = null, FieldFlags Flags = FieldFlags.None)

Parameters

Name string
LookupSource string
Group string
TitleKey string
Flags FieldFlags

Returns

FieldDef

AddTextBlob(string, string, string, FieldFlags)

Adds and returns a text blob field.

public FieldDef AddTextBlob(string Name, string Group = null, string TitleKey = "", FieldFlags Flags = FieldFlags.None)

Parameters

Name string
Group string
TitleKey string
Flags FieldFlags

Returns

FieldDef

AssignLookupSnapshots(DataRow, FieldDef, LookupSource, LookupItem)

Assigns lookup snapshot values to a target row.

public void AssignLookupSnapshots(DataRow TargetRow, FieldDef LookupField, LookupSource LookupSource, LookupItem LookupItem)

Parameters

TargetRow DataRow
LookupField FieldDef
LookupSource LookupSource
LookupItem LookupItem

BuildSql(BuildSqlFlags)

Builds SQL statements for this table descriptor.

public TableSqls BuildSql(BuildSqlFlags Flags)

Parameters

Flags BuildSqlFlags

Returns

TableSqls

CheckDescriptor()

Throws an exception if this descriptor is not fully defined

public override void CheckDescriptor()

CheckTopTableErrors()

Checks the top table for errors and throws an exception if any.

public void CheckTopTableErrors()

CreateDescriptorTable(SqlStore)

Creates a DataTable based on a descriptor.

Creates the look-up tables too if a flag is specified.

The table may added to a list using a specified delegate.

public MemTable CreateDescriptorTable(SqlStore Store)

Parameters

Store SqlStore

Returns

MemTable

FieldExists(string)

Returns true if the specified field name exists in this descriptor.

public bool FieldExists(string FieldName)

Parameters

FieldName string

Returns

bool

FindAnyField(string)

Finds and returns, if exists, a field that has NameOrAlias Name or Alias. It searches this table descriptor and its joined tables in the full tree. Returns null if a field not found.

public Tuple<TableDef, FieldDef> FindAnyField(string NameOrAlias)

Parameters

NameOrAlias string

Returns

Tuple<TableDef, FieldDef>

FindAnyFieldTitle(string)

Finds a field title by searching the whole tree of fields.

public string FindAnyFieldTitle(string NameOrAlias)

Parameters

NameOrAlias string

Returns

string

FindAnyJoinTable(string)

Searces the whole joined tree for a table by a Name or Alias and returns a JoinTableDescriptor, if any, else null.

public TableDef FindAnyJoinTable(string NameOrAlias)

Parameters

NameOrAlias string

Returns

TableDef

FindAnyJoinTableByMasterKeyField(string)

Searces the whole joined tree for a join table descriptor by MasterKeyField and returns that table, if any, else null.

public TableDef FindAnyJoinTableByMasterKeyField(string MasterKeyField)

Parameters

MasterKeyField string

Returns

TableDef

FindField(string)

Finds a field by name, if any, else null.

public FieldDef FindField(string FieldName)

Parameters

FieldName string

Returns

FieldDef

FindJoinTableByMasterKeyField(string)

Finds a join table descriptor by MasterKeyField, if any, else null.

public TableDef FindJoinTableByMasterKeyField(string MasterKeyField)

Parameters

MasterKeyField string

Returns

TableDef

GetBindableFields()

Returns the list of bindable fields.

public List<FieldDef> GetBindableFields()

Returns

List<FieldDef>

GetBindableGroups()

Returns the list of field groups that are not bindable.

public Dictionary<string, List<FieldDef>> GetBindableGroups()

Returns

Dictionary<string, List<FieldDef>>

GetField(string)

Gets a field by name, if any, else exception.

public FieldDef GetField(string FieldName)

Parameters

FieldName string

Returns

FieldDef

GetTopTableErrors()

Returns the errors of the top table.

public string GetTopTableErrors()

Returns

string

IsLocatorSnapshotField(FieldDef)

Returns true when a field is a snapshot target of a locator field.

public bool IsLocatorSnapshotField(FieldDef Field)

Parameters

Field FieldDef

Returns

bool

SetupFieldsDisplayLabelsFor(DataTable, Dictionary<string, string>)

Setups column titles for Table columns using the DisplayLabes dictionary and the TableDes TableDescriptor.

public void SetupFieldsDisplayLabelsFor(DataTable Table, Dictionary<string, string> DisplayLabels)

Parameters

Table DataTable
DisplayLabels Dictionary<string, string>

UpdateFrom(DataTable)

Updates this descriptor information using a specified DataTable schema.

public void UpdateFrom(DataTable Table)

Parameters

Table DataTable

UpdateReferences()

Updates references such as when an instance has references to other instances, e.g. tables of a module definition.

public override void UpdateReferences()