Telerik OpenAccess Classic

Telerik OpenAccess ORM Send comments on this topic.
How to: Work with ClassID and discriminator column
Programmer's Guide > OpenAccess ORM Classic (Old API) > OpenAccess Tasks > Working with Objects > How to: Work with ClassID and discriminator column

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.

OpenAccess needs a type or class identifier for proper type resolution in the following cases:

  1. The IObjectId instance has to know the type of the object that it is referring to, so that the right table can be accessed to retrieve the real object.
  2. The discriminator column value that defines which row in the database to which type in the persistent model belongs to. This is only necessary if the type is part of a class hierarchy.
The class id can be different from the discriminator value. Both can be set independently but have the same value per default.

OpenAccess uses several techniques for generating those unique identifiers.

Class ID Value:

The default class ID value for each class is the hash value generated from the fully qualified class name. For each class its class ID is unique.

Retrieval:

The class id can be retrieved like:

C# Copy Code
scope.PersistentMetaData.GetPersistentTypeDescriptor(typeof(classType)).ClassId;
VB.NET Copy Code
scope.PersistentMetaData.GetPersistentTypeDescriptor(GetType(classType)).ClassId

The class id that can later be used to identify certain classes.
Note: the class id can be changed from the .config file using the corresponding attribute – “class-id”.

app.config Copy Code
<class name="Pet">
     <extension key="class-id" value="4711" />
</class>

Discriminator Value:

If nothing is specified in the configuration file the class id is used as discriminator values by default. The discriminator column itself is used to distinguish between different classes when class hierarchies are mapped flat or vertical. The idea behind the flat and vertical mapping is that every class is mapped into a single row in the base class table. The discriminator value is used to define the type of each row. The discriminator value can be generated using 3 different strategies in the backend configuration wizard:

  1. {hash} –the default strategy. When {hash} or nothing is specified the discriminator column value will be the same as the class id. The discriminator column is mapped to an SQL INTEGER column.
  2. {name} –name strategy means that the discriminator column will be mapped to SQL type VARCHAR and the class name will be used as value.
  3. {fullname} –specifies that the full name of the class (namespace + classname) will be used for creating the discriminator value. In this case again the discriminator column is mapped to SQL VARCHAR.
  4. {no} – this option specified that no discriminator column will be used, this can only be specified for vertical mapped class hierarchies and leads to more complicated sql to determine the type of a row.

Retrieval:

The discriminator column value can be obtained using this code:

C# Copy Code
scope.PersistentMetaData.GetPersistentTypeDescriptor(typeof(classType)).DiscriminatorValue
Example Title Copy Code
scope.PersistentMetaData.GetPersistentTypeDescriptor(GetType(classType)).DiscriminatorValue
The following will return null if the class is not part of a class hierarchy as in this case no discriminator value will be needed.

The discriminator column can be changed from the configuration file using the corresponding attribute – “db-class-id”.

app.config Copy Code
<class name="Pet">
    
<extension key="db-class-id" value="{no}" />
</
class>