Data Access has been discontinued. Please refer to this page for more information.

HighLowKeyGenerator Configuration

The HighLowKeyGeneratorConfiguration class allows you to configure the runtime settings for the HighLow key generator. This is useful for the cases where you use a Guid primary key, but you still need to associate your persistent type with a unique value, so that it makes a more user readable URL. Such unique values can be obtained based on the HIGHLOW key generation algorithm. This functionality is exposed via an API and it allows you to obtain unique values (for non-primary key fields) for a specified string. The OpenAccessContext exposes a method named GetUniqueId, which can be used to get a unique id for a placeholder string. The HighLow Key Generator functionality can be configured in two ways:

The HighLowKeyGeneratorConfiguration object is accessible through the HighLowKeyGenerator property that is exposed by the BackendConfiguration class.

For more information about the HightLow Keygen API, please refer to Working with HighLow Keygen API.

public partial class FluentModel
{
   static FluentModel()
   {
       BackendConfiguration.HighLowKeyGeneratorConfiguration highLowConfig = 
            backend.HighLowKeyGenerator;
   }
}
Partial Public Class FluentModel
    Shared Sub New()
        Dim highLowConfig As BackendConfiguration.HighLowKeyGeneratorConfiguration = 
            backend.HighLowKeyGenerator
    End Sub
End Class

The HighLowKeyGeneratorConfiguration class exposes the following properties:

  • GrabSize - controls the minimal number of new keys fetched in one server call. Default value is 10.
  • Start - controls the starting value as given out by the generator. Default value is 0.
  • IgnoreMissingTables - controls the check during database open operation. If a table is missing in the actual database the keygen table entry will not be written and no objects can be created. Default value is false.

Configuring the HighLow Key Generator Functionality via Code

To configure the HighLow key generator functionality in the code, you need to extend your context class with another partial class with the same name and implement the CustomizeBackendConfiguration partial method. Using the config argument you can setup the HighLowKeyGenerator configuration for your context. For example:

public partial class FluentModel
{
    static partial void CustomizeBackendConfiguration(ref BackendConfiguration config)
    {
        config.HighLowKeyGenerator.GrabSize = 20;
        config.HighLowKeyGenerator.IgnoreMissingTables = true;
        config.HighLowKeyGenerator.Start = 5;
    }
}
Partial Public Class FluentModel

    Private Shared Sub CustomizeBackendConfiguration(ByRef config As BackendConfiguration)
        config.HighLowKeyGenerator.GrabSize = 20
        config.HighLowKeyGenerator.IgnoreMissingTables = True
        config.HighLowKeyGenerator.Start = 5
    End Sub

End Class

Configuring the HighLow Key Generator Functionality via Config File

Another way to configure the HighLow key generator functionality is to define the configuration in the App/web config file. For example:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
 <configSections>
   <section name="openAccessConfiguration"
            type="Telerik.OpenAccess.Config.OpenAccessConfigSectionHandler, Telerik.OpenAccess"
            requirePermission="false" />
 </configSections>
 <openAccessConfiguration>
   <backendConfiguration name="HighLowKeyConfiguration">
     <highLowKeyGenerator grabSize="20"
                          start ="5"
                          ignoreMissingTables ="true" />
   </backendConfiguration>
 </openAccessConfiguration>
 <connectionStrings>
 </connectionStrings>
</configuration>

Again, you need to extend your context class with another partial class with the same name and add the following static constructor:

public partial class FluentModel
{
   static FluentModel()
   {
       BackendConfiguration.MergeBackendConfigurationFromConfigFile(
            backend,
            ConfigurationMergeMode.ConfigFileDefinitionWins,
            "HighLowKeyConfiguration" );
   }
}

Partial Public Class FluentModel
    Shared Sub New()
        BackendConfiguration.MergeBackendConfigurationFromConfigFile(backend, 
            ConfigurationMergeMode.ConfigFileDefinitionWins, "HighLowKeyConfiguration")
    End Sub
End Class