There are various properties that govern how the OpenAccess ORM runtime behaves. The default values for these settings usually suffice for most situations. In case you need to tweak some settings, this can be done via the ‘Backend settings’ tab in the ‘Model settings’ dialog available in the Visual Studio designer. These options are broadly divided into 4 categories (here you can find more information about this dialog and the settings available):
When any setting is changed in this dialog and the .rlinq file is saved, OpenAccess generates the appropriate code to set the modified values in the configuration. If you open the code-behind file for the OpenAccessContext derived class you will notice a static method ‘GetBackendConfiguration’. This method is responsible for providing a ‘Telerik.OpenAccess.BackendConfiguration’ instance with all the specified settings. Here is what is generated when the ‘2nd Level Cache’ is enabled via the ‘Model Settings’ dialog:
Apart from the settings available via the ‘Model settings’ dialog there are also certain advanced settings that can be made to the configuration. In order to keep the options in the dialog easy to understand and use, these advanced settings are not available there, but nevertheless can be easily set them in code. Let us look at an example.
Recently we introduced a property that dictates the behavior of the run-time when values of a ‘Deleted’ entity (not yet committed) are accessed - the ‘AllowReadAfterDelete’ property. This option is not available via the ‘Model settings’ dialog, so let us see how to set this property through code:
The static method ‘GetBackendConfiguration’ is called first to initialize the static member – ‘backend’, and then the static constructor further sets the advanced properties. This way you can add other settings that are not present in the ‘Model settings’ via code. Note that modifying the generated ‘GetBackendConfiguration’ method by adding the advanced property settings will not work as the context class is regenerated every time you save the .rlinq file. Hence you would need the static constructor within a partial class.
Subscribe to be the first to get our expert-written articles and tutorials for developers!