Telerik OpenAccess Classic

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

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.

Interfaces are not persistent by default; an interface itself has to be made persistent like classes. You have to make interfaces persistent by applying the [Persistent] attribute to the interface definition.

Reference fields of Interface type are mapped to two or more columns. The first column identifying the type of the referenced instance and the other column(s) for holding its primary key(s). You can configure which classes are allowed and define the mapping between classes and type codes.

If no classes are listed then any persistence capable class with a primary key that is compatible with the columns defined in the mapping is allowed. If no valid classes are listed then the class-id of the referenced class is used as a value for the class (or type) column.

If all the discriminator values are integer values then the default class column will be an int (INTEGER). If any of the values are not int values then a String (VARCHAR) column is created. You can edit the column properties in the XML metadata as in the following example:

Copy Code
<field name="owner">
<extension key="valid-class" value="Restaurant=R" />
<extension key="valid-class" value="Supplier=S" />
<extension key="db-class-id">
<extension key="db-column">
<extension key="db-length" value="10" />

In case of the above example, the reference field owner can point to either Restaurant or Supplier, which have been type-coded to "R" and "S" respectively. If the type codes had not been specified then the class-id of the referenced classes would have been used as the referenced id column.

Please keep the following things in mind about type coding:


Either all the valid classes for the interface should be type-coded or none of them should be type-coded.


Once the valid class/classes have been type-coded and if you want to remove the type-codes, the same will have to deleted manually from the database.


If there is any change in the type coding for a valid class/classes, the same will have to be done manually in the database.

Interface or Object Reference to Composite Primary Key

All classes that will be referenced must have the same number of primary key columns. In addition the columns must be compatible in an SQL sense as OpenAccess ORM will generate joins for queries involving the reference. If you list valid classes for the reference then the primary key of the first class in the list will be used as a template for the default reference column(s). If you do not list any valid classes then an int (INTEGER) column is assumed. This will hold a reference to any class that uses internal identity.

Currently OpenAccess ORM does not support interface types of collections or dictionaries, or queries against the extent of an interface type (i.e., using an interface as a candidate class for a query).

Efficient queries through interface and Object references are supported via casting to a persistent class. They are executed entirely in SQL.