How to: Programatically Configure the OpenAccessContext

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 model 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 model in a separate code file.
  2. In the new code file for the context class implement the CustomizeBackendConfiguration partial method.

    public partial class FluentModel
    {   
        static partial void CustomizeBackendConfiguration(ref BackendConfiguration config)
        {
        }
    }
    
    Partial Public Class FluentModel
    
        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 FluentModel
    {   
        static partial void CustomizeBackendConfiguration(ref BackendConfiguration config)
        {
            config.Runtime.AllowReadAfterDelete = true;
            config.SecondLevelCache.Enabled = true;
            config.SecondLevelCache.NumberOfObjects = 6000;
        }
    }
    
    Partial Public Class FluentModel
    
        Private Shared Sub CustomizeBackendConfiguration(ByRef config As BackendConfiguration)
            config.Runtime.AllowReadAfterDelete = True
            config.SecondLevelCache.Enabled = True
            config.SecondLevelCache.NumberOfObjects = 6000
        End Sub
    
    End Class