Back to Devexpress

Store Application Model Differences in the Database

expressappframework-113698-ui-construction-application-model-ui-settings-storage-application-model-storages-store-the-application-model-differences-in-the-database.md

latest4.9 KB
Original Source

Store Application Model Differences in the Database

  • Mar 03, 2026
  • 4 minutes to read

When you create a new application with the Security System enabled in the Template Kit, XAF stores user settings (model differences) in the database with the help of the ModelDifferenceDbStore storage (the default setting). This topic describes how to enable this feature in an existing application and how to store shared model differences (administrator settings) in the database.

Note

When the Security System is disabled, XAF passes the System.Security.Principal.WindowsIdentity.GetCurrent().Name value the IModelDifference.UserId property to use as user identifier. You can use the technique described in this article to enable ModelDifferenceDbStore in unsecured Windows Forms applications. XAF supports shared model differences for ASP.NET Core Blazor and Windows Forms when the Security System is disabled.

  1. Depending on the platform, navigate to one for the following files:

  2. In the overridden ModuleBase.Setup method, subscribe to the XafApplication.CreateCustomModelDifferenceStore and XafApplication.CreateCustomUserModelDifferenceStore events.

  3. In these event handlers, pass the ModelDifferenceDbStore instance to the e.Store parameter. Pass the ModelDifference type to the ModelDifferenceDbStore constructor. Here, ModelDifference is a built-in persistent object from the DevExpress.Persistent.BaseImpl namespace (for XPO) or from the DevExpress.Persistent.BaseImpl.EF namespace (for Entity Framework Core) that implements the IModelDifference interface.

  4. Set the last parameter of the ModelDifferenceDbStore constructor (used to initialize the IModelDifference.ContextId property) to "Blazor" (ASP.NET Core Blazor) or "Win" (Windows Forms). This is necessary to distinguish between model differences created for the same user on different platforms.

  5. Navigate to the YourSolutionName.Module\Module.cs file and add the following code to the Module constructor:

  6. If you use Entity Framework Core, additionally register ModelDifference and ModelDifferenceAspect classes in DbContext.

  7. In the MySolution.Module\DatabaseUpdate\Updater.cs file, check that all users have read/write access to ModelDifference and ModelDifferenceAspect types.

Tip

For information on how you can enable UI elements to manage Model Differences stored in the database, refer to the following article - How to: Enable the Administrative UI for managing Users’ Model Differences.

Note

The following features should not be used together:

With this configuration, your application loads information on custom persistent fields from the database and then updates the database schema. However, a thread-safe data layer does not support altering the data model after the database connection is established.