Telerik OpenAccess Classic

Telerik OpenAccess ORM Send comments on this topic.
Programmer's Guide > OpenAccess ORM Classic (Old API) > Programming With OpenAccess > Metadata Extension Reference > db-key-generator

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.

A key generator provides the primary key values. A key generator, generates identity field values automatically. The db-key-generator defines the primary key generator for a class. The value attribute specifies the name of a built-in key generator. The first time a db-key-generator class is encountered in the metadata an instance is created and stored for later use.

OpenAccess ORM currently supports the following key generators:



HIGHLOW key generator – It is the default key generator and it uses a lookup table (the HIGHLOW or sequence block algorithm), i.e. it uses a last_used table to generate the id for a new instance.



AUTOINC key generator – Using identity or auto increment columns.



Verify – It checks whether the key field has been specified wherever required and it also verifies that one of the key fields have a non-default value during ObjectScope.Add.



GUID – GUID as a key generator will be usable where new Guid values are required by the single field identity or multiple field identity.



None – The application has to provide the key.

A sample of the XML metadata is shown below:

Copy Code
<class name="Branch">
   <extension key="db-key-generator" value="AUTOINC" />

Properties for the HIGHLOW key generator






Name of the keygen lookup table



Name of the primary key column



Name of the last used number column



Length of the primary key column



The number of instances created per keygen table update. Using a grabSize > 1 improves performance but may result in "holes" in the sequence



If a table has no keygen row and start is 0 then the first primary key will be "select max (id) from table" + 1. Otherwise start is the first primary key



If false the keygen table is left out of the generated schema



Name of the primary key constraint for the keygen table

OpenAccess ORM allows you to use a user-defined table as source for the HIGHLOW Key generator keys, for advanced tasks. In order to use this you need to change the default properties of the HIGHLOW Key generator. This could include simple things like changing the default grabSize value, in order to have less number of round-trips to the database for mass creating objects or changing the start value to fit into existing numbering, up to advanced task like defining you own table name, key column name and so on.

The changes to the default properties for the HIGHLOW key generator need to be made in the App.config file, in the Backend configurations section. Refer to Using the integrated HIGHLOW generator with a user defined table to know the exact changes needed to be made in the App.config file.