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

How to: Programatically Configure the OpenAccessContext

This article is relevant to entity models that utilize the deprecated Visual Studio integration of Telerik Data Access. The current documentation of the Data Access framework is available here.

This article will show you how you can configure the BackendConfiguration object of the context class of your model programatically.

When the context class of your Domain Model (the one that derives from OpenAccessContext) is initialized, it uses the GetBackendConfiguration method to create a BackendConfiguration object for the currently used backend. You can use this object to customize the configuration of the context. The CustomizeBackendConfiguration is the recommended extension point for this task as it is called by GetBackendConfiguration:

  1. Extend the partial context class of your Domain Model in a separate code file.
  2. In the new code file for the context class implement the CustomizeBackendConfiguration partial method.

    public partial class EntitiesModel
    {   
        static partial void CustomizeBackendConfiguration(ref BackendConfiguration config)
        {
        }
    }
    
    Partial Public Class EntitiesModel
    
        Private Shared Sub CustomizeBackendConfiguration(ByRef config As BackendConfiguration)
        End Sub
    
    End Class
    
  3. Use the BackendConfiguration argument config to customize the configuration of your model`s context.

    public partial class EntitiesModel
    {   
        static partial void CustomizeBackendConfiguration(ref BackendConfiguration config)
        {
            config.Runtime.AllowReadAfterDelete = true;
            config.SecondLevelCache.Enabled = true;
            config.SecondLevelCache.NumberOfObjects = 6000;
        }
    }
    
    Partial Public Class EntitiesModel
    
        Private Shared Sub CustomizeBackendConfiguration(ByRef config As BackendConfiguration)
            config.Runtime.AllowReadAfterDelete = True
            config.SecondLevelCache.Enabled = True
            config.SecondLevelCache.NumberOfObjects = 6000
        End Sub
    
    End Class