ComponentOne DataObjects for .NET
Table Fields
DataObjects for .NET (Enterprise Edition) > Schema Objects > Simple Tables > Table Fields

Table fields determine the structure of a table row. In a bound table (see Bound, SQL-Based and Unbound Tables), fields usually correspond to database fields of the database table. However, they do not have to be in exact one-to-one correspondence with database fields. Fields order can be changed, some fields can be deleted from the table, and new fields can be added. If necessary, multiple fields can represent a single database field. The database field represented by a table field is determined by the DbFieldName property. This property can be empty, which means that the field is not based on (not bound to) a database field. Such fields are called unbound, or calculated.

A field has a name that must be unique in the table. A field can be renamed by renaming the field node in the Fields list. The name is used to identify the field as a property of the business object associated with the table, see Using Typed Data Objects in Business Logic. It is also used as the name of the column exposed to the users, and as the default display name (caption) of the column.

The DataType property determines the field .NET type, and NativeDbType – its native database or OLE DB type. Both DataType and NativeDbType are set by Import Wizard when a table is first created in database structure import, see Importing Database Structure. DataType is the field's most important characteristic, it affects all DataObjects for .NET functions. Normally, Field.DataType should not be changed after importing structure from the database. Adding a new field to a table, you must set its DataType property. NativeDbType is used only for updating values in the database, and can be set to Any (-1), in which case its value is effectively ignored. When in doubt, use Any (-1) as the default value for NativeDbType.

The following properties determine the field's additional storage characteristics:

Property Description
AllowDbNull Gets or sets a value indicating whether null or empty string values are allowed in this field. If it is set to False, an attempt to assign null or empty string value to this field generates an exception.
AutoIncrement Gets or sets a value indicating whether the field automatically receives an incremented value for a new row added to the table.
AutoIncrementSeed Gets or sets the starting value for a field with AutoIncrement not None.
AutoIncrementStep Gets or sets the increment a field with AutoIncrement not None.
MaxLength Gets or sets the maximum length of a string field, in characters. If the length is unlimited, the value is 0 (default).
Precision For numeric fields (NativeDbType is Numeric, Decimal, or DbTimeStamp), this property sets or gets the maximum number of digits representing values.
Scale For numeric fields (NativeDbType is Numeric, Decimal, or DbTimeStamp), this property sets or gets the scale of numeric values, that is, how many digits to the right of the decimal point are used to represent values.
Unique Gets or sets a value indicating whether the values of this field in each row must be unique. If it is set to True, an attempt to assign a duplicate value to this field generates an exception.

The PrimaryKey property determines whether the field belongs to the table's primary key. The table's primary key, the sequence of field names constituting the primary key, is returned by the PrimaryKey read-only property. Each modifiable table must have primary key, that is, at least one field where the PrimaryKey property is set to True. Primary key values must be unique in table rows; an attempt to set a duplicate primary key generates an exception.

Each field can have one or more calculation expressions associated with it in the Calculations property, a collection of FieldCalculationInfo objects. Usually, calculation expressions are used in calculated (unbound) fields, although they can be useful in bound fields as well. A field is called unbound if its DbFieldName property is empty. DataObjects for .NET automatically computes calculated field values and automatically refreshes them when any of the arguments of its calculation expression(s) changes. Calculation expressions can contain fields of the same table as well as of its parent and child tables with respect to relations. Child fields are used with aggregation functions to perform grouping and aggregation. See DataObjects for .NET Expressions for a description of DataObjects for .NET expression language.

Each calculation (FieldCalculationInfo) contains Expression, which is the expression used to obtain field values, and two additional properties: Condition and FireEvent. Condition is an optional Boolean expression determining the calculation's applicability. If Condition evaluates to False, the calculation expression is not evaluated. If a field has multiple calculations, DataObjects for .NET applies the first with the Condition expression evaluating to True. If none is applicable, the field value is left unchanged. FireEvent is a Boolean property set to False by default. If it is set to True, setting the value from calculation expression triggers the same sequence of events (BeforeFieldChange, AfterFieldChange, AfterChanges) as if the value has been modified by the end user.

Field calculations are useful for bound fields as well as for calculated fields. In this case, they are usually qualified by Condition expressions. Depending on the conditions, a field's value can be derived from a value stored in the database, or it can be calculated. For instance, if field A is non-empty, field B always returns the same value as A, but if A is empty, B can be set independently of A.

The following properties control field value modifications:

Property Description
ReadOnly Gets or sets a value indicating whether the field value can be changed by the end user or from event code. If set to True, an attempt to change the field throws an exception.
ReadOnlyUnlessNew Gets or sets a value indicating whether the field value can be changed after the row has been added to the table (after EndAddNew event). If set to True, an attempt to change the field throws an exception unless it is done in a newly added row, before the EndAddNew event.
Constraints Returns the collection of field-level constraints, ConstraintInfo objects. Field-level constraints are evaluated (tested) when the value of the field changes. For a change to be successful, all constraint expressions (Expression) must evaluate to True. If one of the constraints is not satisfied, an exception is thrown. The exception message is determined by ErrorDescription. Constraints with Condition expression (if non-empty) evaluating to False, are skipped, not tested. See also, DataObjects for .NET Expressions for a description of DataObjects for .NET expression language.
DefaultValue Gets or sets the default value, in string representation, for the field in a newly created row.

The following properties control field behavior in updating the database (they only have effect for bound fields, that is, if DbFieldName is not empty):

Property Description
DataSourceReadOnly Gets or sets the value indicating whether the field value in the database can be changed. If this property is set to True, the field value will not be set in the database update operation (as with UpdateSet = Never) and it cannot be modified unless it is done in a newly added row, before the EndAddNew event (as with ReadOnlyUnlessNew = True).
UpdateIgnore Gets or sets the value indicating whether the field value is sent to the database (to the server) for update. If this property is set to True, the field value is not sent to the server for update, even if it has been modified by the user. The default is False.
UpdateLocate Gets or sets the value indicating whether the field value is used to locate the database record that is going to be updated. If it is set to False, the field is not used for locating the database record, regardless of the value of UpdateLocateMode. If it is set to True (default), this is determined by the value of the UpdateLocateMode property. See Updating the Database for details on locating database record for update.
UpdateRefresh Gets or sets the value indicating whether the field value is refreshed, retrieved from the database after updating the database record. If it is set to False, the field value is not refreshed, regardless of the value of UpdateRefreshMode. If it is set to True (default), this is determined by the value of the UpdateRefreshMode property.
UpdateSet Gets or sets the value indicating whether the field value is set in the database record. If it is set to Always, the value in the database is always modified, set to the current field value. If it is set to Never, the value in the database is always left unchanged. If it is set to IfChanged(default), the value in the database is set to the current field value if the current field value is different from the original field value as it was last fetched from the database (the original value can be retrieved using Item (field, DataRowVersionEnum.Original)).

DataObjects for .NET can perform automatic conversion from DbNull to empty string when returning string field values and back from empty string to DbNull when saving string field values. To enable this automatic conversion, set ConvertNullToEmpty/ConvertEmptyToNull for individual fields, or set FieldDefaults:DataSetDef in a data set in the schema (in DataObjects for .NET Express, FieldDefaults) to enable it by default for a whole data set.