Class TableDef
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
ModuleDefModuleDef
Fields
ITEM
Constant
public const string ITEM = "_ITEM_"
Field Value
LINES
Constant
public const string LINES = "_LINES_"
Field Value
SUBLINES
Constant
public const string SUBLINES = "_SUBLINES_"
Field Value
Properties
Alias
An alias of this table
public string Alias { get; set; }
Property Value
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
Details
The detail tables of this table.
public DefList<TableDef> Details { get; set; }
Property Value
FieldGroups
Preferred field group display order.
public List<string> FieldGroups { get; set; }
Property Value
Fields
The fields of this table
public DefList<FieldDef> Fields { get; set; }
Property Value
HasDetails
True when this table has details
[JsonIgnore]
public bool HasDetails { get; }
Property Value
HasJoins
True when this table has joins
[JsonIgnore]
public bool HasJoins { get; }
Property Value
HasStocks
True when this table has stocks
[JsonIgnore]
public bool HasStocks { get; }
Property Value
IsDetail
When true then this is a detail table, e.g. a TradeLines under a Trade table.
public bool IsDetail { get; set; }
Property Value
IsJoin
True when this is a table joined to another table.
[JsonIgnore]
public bool IsJoin { get; }
Property Value
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
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
Joins
The list of join tables.
public DefList<TableDef> Joins { get; set; }
Property Value
KeyField
Gets or sets the name of the primary key field of this table.
public string KeyField { get; set; }
Property Value
Master
The master table when this is a detail table.
[JsonIgnore]
public TableDef Master { get; set; }
Property Value
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
ModuleDef
The master definition this instance belongs to.
[JsonIgnore]
public ModuleDef ModuleDef { get; set; }
Property Value
Owner
When this is a join table, the owner is the table that joins this table.
[JsonIgnore]
public TableDef Owner { get; set; }
Property Value
Sqls
The SQL statements associated with this table.
public TableSqls Sqls { get; set; }
Property Value
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
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
NamestringMaxLengthintGroupstringTitleKeystringFlagsFieldFlags
Returns
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
NamestringGroupstringTitleKeystringFlagsFieldFlags
Returns
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
NamestringGroupstringTitleKeystringFlagsFieldFlags
Returns
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
NamestringGroupstringTitleKeystringFlagsFieldFlags
Returns
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
NamestringGroupstringTitleKeystringFlagsFieldFlags
Returns
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
NamestringGroupstringDecimalsintTitleKeystringFlagsFieldFlags
Returns
AddDetail(string, string, string)
Adds a detail table to this table.
public TableDef AddDetail(string DetailTableName, string MasterField, string DetailField)
Parameters
Returns
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
NamestringGroupstringDecimalsintTitleKeystringFlagsFieldFlags
Returns
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
NamestringLookupSourcestringEnumTypeTypeGroupstringUseNullItemboolTitleKeystringFlagsFieldFlags
Returns
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
NamestringDataTypeDataFieldTypeGroupstringTitleKeystringAliasstringMaxLengthintDecimalsintLookupSourcestringLocatorstringFlagsFieldFlags
Returns
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
NamestringDataTypeDataFieldTypeFlagsFieldFlagsMaxLengthint
Returns
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
NamestringFlagsFieldFlags
Returns
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
NamestringGroupstringTitleKeystringFlagsFieldFlags
Returns
AddIntegerId(string, FieldFlags)
Adds and returns an integer Id field
public FieldDef AddIntegerId(string Name = "Id", FieldFlags Flags = FieldFlags.Hidden | FieldFlags.Required)
Parameters
NamestringFlagsFieldFlags
Returns
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
NamestringLookupSourcestringGroupstringTitleKeystringFlagsFieldFlags
Returns
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
OwnKeyFieldstringA field that belongs to this table. Is used in the join SQL statement
ForeignTablestringThe name of the table to join, e.g. COUNTRY to CUSTOMER
ForeignAliasstringThe alias of the table to join, e.g.
coForeignPrimaryKeystringThe primary key field name of the table to join, e.g.
Id
Returns
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
OwnKeyFieldstringA field that belongs to this table. Is used in the join SQL statement
LocatorstringThe locator name to be used in the owner key field.
ForeignTablestringThe name of the table to join, e.g. COUNTRY to CUSTOMER
ForeignAliasstringThe alias of the table to join, e.g.
coForeignPrimaryKeystringThe primary key field name of the table to join, e.g.
Id
Returns
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
NamestringDataTypeDataFieldTypeLookupSourcestringGroupstringTitleKeystringFlagsFieldFlags
Returns
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
NamestringMaxLengthintGroupstringTitleKeystringFlagsFieldFlags
Returns
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
NamestringFlagsFieldFlagsMaxLengthint
Returns
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
NamestringLookupSourcestringGroupstringTitleKeystringFlagsFieldFlags
Returns
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
NamestringGroupstringTitleKeystringFlagsFieldFlags
Returns
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
TargetRowDataRowLookupFieldFieldDefLookupSourceLookupSourceLookupItemLookupItem
BuildSql(BuildSqlFlags)
Builds SQL statements for this table descriptor.
public TableSqls BuildSql(BuildSqlFlags Flags)
Parameters
FlagsBuildSqlFlags
Returns
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
StoreSqlStore
Returns
FieldExists(string)
Returns true if the specified field name exists in this descriptor.
public bool FieldExists(string FieldName)
Parameters
FieldNamestring
Returns
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
NameOrAliasstring
Returns
FindAnyFieldTitle(string)
Finds a field title by searching the whole tree of fields.
public string FindAnyFieldTitle(string NameOrAlias)
Parameters
NameOrAliasstring
Returns
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
NameOrAliasstring
Returns
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
MasterKeyFieldstring
Returns
FindField(string)
Finds a field by name, if any, else null.
public FieldDef FindField(string FieldName)
Parameters
FieldNamestring
Returns
FindJoinTableByMasterKeyField(string)
Finds a join table descriptor by MasterKeyField, if any, else null.
public TableDef FindJoinTableByMasterKeyField(string MasterKeyField)
Parameters
MasterKeyFieldstring
Returns
GetBindableFields()
Returns the list of bindable fields.
public List<FieldDef> GetBindableFields()
Returns
GetBindableGroups()
Returns the list of field groups that are not bindable.
public Dictionary<string, List<FieldDef>> GetBindableGroups()
Returns
GetField(string)
Gets a field by name, if any, else exception.
public FieldDef GetField(string FieldName)
Parameters
FieldNamestring
Returns
GetTopTableErrors()
Returns the errors of the top table.
public string GetTopTableErrors()
Returns
IsLocatorSnapshotField(FieldDef)
Returns true when a field is a snapshot target of a locator field.
public bool IsLocatorSnapshotField(FieldDef Field)
Parameters
FieldFieldDef
Returns
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
TableDataTableDisplayLabelsDictionary<string, string>
UpdateFrom(DataTable)
Updates this descriptor information using a specified DataTable schema.
public void UpdateFrom(DataTable Table)
Parameters
TableDataTable
UpdateReferences()
Updates references such as when an instance has references to other instances, e.g. tables of a module definition.
public override void UpdateReferences()