CDAL Attribute Tags
Classes and their properties in MineMarket are tagged with attributes that define table and column names. Classes map to tables and properties map to columns. For example, the following class is an AnalyteDef object that maps to the AnalyteDef database table as defined by the DataTable attribute. This object inherits from BTNamedBusinessObject.
[DataTable("AnalyteDef")]
[TypeConverter(typeof(GenericBTObjectConverter))]
[ObjectCategory("Quality", "Analyte Definition")]
public sealed class AnalyteDef : BTNamedBusinessObject, IExtendedObject
The following example is the column mapping for the DefaultBasis property on the AnalyteDef object and is defined by the DataFieldAttribute called BasisID.
The parameter false indicates that the value cannot be null. The parameter typeof indicates the data type of the column value, which in this case is a BTKey. Other types include string, int and double.
DefaultBasis is another MineMarket object of type Basis, as indicated by the return type of the method and is therefore a foreign key in the database.
[DataFieldAttribute("BasisID", false, typeof(BTKey))]
public Basis DefaultBasis
{
get {return mDefaultBasis;}
set
{
mOldValue = mDefaultBasis;
mDefaultBasis = value;
base.PropertyChanged("DefaultBasis", value);
}
}
As a result of the above example, in the MineMarket database there will be an AnalyteDef table with a foreign key field called BasisID that holds a BTKey (int) value. From a database perspective, the value can be null but CDAL will not allow the value to be persisted if it is null.
The following image is a screenshot of the database structure with the CDAL attribute tag.
The following image is a screenshot of the entity relationship diagram.
The following query returns a list of analytes with their basis. The name column is inherited from BTNamedBusinessObject.
select a.Name as 'Analyte', b.Name as 'Basis'
from AnalyteDef a, Basis b
where a.BasisID = b.BasisID
The ID column name of an object (in this case BasisID) is defined as follows on the Basis class. However, from an object perspective, the property name is ID even though the column name in the database is BasisID.
[DataField("BasisID", false, typeof(BTKey))]
public override BTKey ID
{
get
{
return base.mID;
}
}