Telerik OpenAccess Classic

Telerik OpenAccess ORM Send comments on this topic.
Mapping Value References
Programmer's Guide > OpenAccess ORM Classic (Old API) > Programming With OpenAccess > Mapping > Simple and Reference Fields > Mapping Value References

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.

Value references extend reference types; it is a special case where the reference becomes another variable or record field, thereby making it possible to access and display the referenced field in a datagrid as a string value, without having to use an sql join or retrieve the complete object.

With value references, therefore it becomes possible to access a database column, from within a class, as a field, and to run queries on the values of the column; and secondly, it is also possible to reference another object.

An example to illustrate this point: If you have a Order class defined as below:

C# Copy Code
public class Order
{
 
private int orderID; // pk
 
private DateTime orderDate;
 
private Customer customer;
.......
}
VB .NET Copy Code
Public Class Order
  Private orderID As Integer ' pk
  Private orderDate As DateTime
  Private customer As Customer
 .......
End Class

Now if we want to use customer as a reference to the Order class and also to display the value of the customer (CustomerID) as a string in datagrids and as a value in queries, without having to retrieve the customer record, we have to make changes to the mapping as described below.

The generated mapping class and the generated class must be expanded with an additional field from type string in the class; the string customerID in this example, and the mapping code must be changed from:

Copy Code
<field name="customer">
 
<extension key="db-column">
   
<extension key="db-type" value="CHAR" />
   
<extension key="db-column-name" value="CustomerID" />
   
<extension key="db-length" value="5" />
 
</extension>
</
field>

to

Copy Code
<field name="customer">
 
<extension key="db-column">
   
<extension key="db-type" value="CHAR" />
   
<extension key="db-column-name" value="CustomerID" />
   
<extension key="db-length" value="5" />
 
</extension>
</
field>
Copy Code
<field name="customerID">
 
<extension key="db-column">
   
<extension key="db-type" value="CHAR" />
   
<extension key="db-column-name" value="CustomerID" />
   
<extension key="db-length" value="5" />
 
</extension>
</
field>

And the class Order, which has been defined above, also needs to be changed to:

C# Copy Code
public class Order
{
 
private int orderID; // pk
 
private DateTime orderDate;
 
private Customer customer;
 
private string customerID;
.......
}
VB .NET Copy Code
Public Class Order
  Private orderID As Integer ' pk
  Private orderDate As DateTime
  Private customer As Customer
  Private customerID As String
  .......
End Class

If the string customerID is changed inside the application, the reference to the orders can be broken.

You should only use the value field to display and not to change the reference; and therefore please make the customerID field content read-only.