Telerik OpenAccess Classic

Telerik OpenAccess ORM Send comments on this topic.
Artificial Fields
Programmer's Guide > OpenAccess ORM Classic (Old API) > Programming With OpenAccess > Artificial Fields and Types > Artificial Fields

Glossary Item Box

This documentation article is a legacy resource describing the functionality of the deprecated OpenAccess Classic only. The contemporary documentation of Telerik OpenAccess ORM is available here.

Artificial fields are fields that extend the structure of a persistent class by adding new persistent fields during runtime. These new fields are described in XML configuration entries. The root node of the XML section describing the artificial fields as well as the types is the <artificial> node.  Below is an example of an XML structure that describes a sample artificial field:

app.config Copy Code
<artificial>
     
<mapping id="artificialMapping">
       
<namespace name="FirstStepsClasses">
         
<class name="Person">
           
<field name="age" clr="System.Int32" />
         
</class>
       
</namespace>
     
</mapping>
   
</artificial>

The second node in the structure after the <artificial> node is the <mapping> node.

app.config Copy Code
<mapping id="artificialMapping">

The mapping node in the artificial section must have a unique ID. It means that in all cases it should be different than the mapping nodes available for the persistent-capable classes (in most cases generated automatically by the OpenAccess wizards).

Next two nodes are the <namespace> and <class> nodes where we specify the full name of the persistent class that is going to be extended with artificial fields.

app.config Copy Code
       <namespace name="FirstStepsClasses">
         
<class name="Person">

Inside the class node, there is a field node which has two attributes: name and clr.

app.config Copy Code
<field name="age" clr="System.Int32" />

The ‘name’ attribute specifies the name of the field and its value is used to manage the field via the Generic Metadata Access API. Here is a code sample that shows how a property descriptor for the ‘age’ artificial field is being obtained.

C# Copy Code
IPersistentTypeDescriptor ptd = scope.PersistentMetaData.GetPersistentTypeDescriptor(typeof(Person));
           PropertyDescriptorCollection pdc = ptd.GetProperties();
PropertyDescriptor pd = pdc
[“”;
VB.NET Copy Code
Dim ptd As IPersistentTypeDescriptor = scope.PersistentMetaData.GetPersistentTypeDescriptor(GetType(Person))
            Dim pdc As PropertyDescriptorCollection = ptd.GetProperties()
Dim pd As PropertyDescriptor = pdc(“age”)

The ‘clr’ attribute specifies the CLR type of the artificial field. Artificial fields can be of any normal CLR type, their type can be another persistent class(artificial reference) or a generic collection.
Below are some example entries of those kinds:

 

app.cofnig Copy Code
<artificial>
      <mapping id="ArtificialMapping">
        <namespace name=" FirstStepsClasses">
          <class name="FootballPlayer">
            <field name="age" clr="System.Int32" />
            <field name="bestFriend" clr=" FirstStepsClasses.Player" />
            <field name="teamMates" clr="Telerik.OpenAccess.TrackedList`1[[FirstStepsClasses.FootballPlayer]]" />
   </class>
        </namespace>
      </mapping>
    </artificial>