Ticket T194320
Visible to All Users

ModelDifferenceDbStore - Always take the latest changes made to the Model.xafml file at design time into account

created 10 years ago (modified 10 years ago)

Prerequisites
By default, starting with v14.2, all new XAF WinForms projects will store administrative (Model.XAFML) and user differences in the database tables (ModelDifference and ModelDifferenceAspect).
This built-in option stems from the How to: Store Model Differences in Database example we had in the past.
This new behavior is plugged-in if the Security System is enabled in the Solution Wizard and is technically done by subscribing to the CreateCustomModelDifferenceStore and CreateCustomUserModelDifferenceStore events within YourSolutionName.Module.Win/Module.xx file. Refer to the eXpressApp Framework > Task-Based Help > How to: Store the Application Model Differences in the Database article for more details.

Problem description
As of v14.2.3, the contents of the Model.XAFML file are once read during the first application run and are stored in the database. Thus, any subsequent changes to the Model.XAFML file during development will not be re-read into the database or ignored. This may confuse newbie developers as they may not understand why their latest model changes are not taken into account.

Current solutions
Take special note that to start reading subsequent customizations from the Model.XAFML file at every application run as it was in the past, you will need to backup and then drop the existing ModelDifference and ModelDifferenceAspect tables in  your test database on your development machine.

1.  Do not subscribe to the CreateCustomModelDifference event (and thus disable storing the Model.XAFML file contents in the database) while debugging. You can use either the preprocessor directives or the System.Diagnostics.Debugger.IsAttached property for that purpose (see the code below).
2. Perform global/administrative Application Model customizations using the runtime Model Editor instead of making changes to the Model.XAFML file at design time (see the code below).

C#
// Example code for #1 and #2. private void Application_CreateCustomModelDifferenceStore(Object sender, CreateCustomModelDifferenceStoreEventArgs e) { #if !DEBUG e.Store = new ModelDifferenceDbStore((XafApplication)sender, true); e.Handled = true; #endif } // Example code for #2 only. private void Application_CreateCustomUserModelDifferenceStore(Object sender, CreateCustomModelDifferenceStoreEventArgs e) { bool isSharedModelDifference = System.Diagnostics.Debugger.IsAttached; e.Store = new ModelDifferenceDbStore((XafApplication)sender, isSharedModelDifference); e.Handled = true; }

3.  Make customizations in the Model.DesignedDiffs.xafml files of your modules where possible. This solution is possible in certain scenarios only, because the Application Model is fully initialized from used modules and application settings only in YourSolution.Win project.
4.  Use the application UI to edit administrative settings, as described in the How to: Enable the Administrative UI for managing Users' Model Differences topic.

5.  Make required customizations using the runtime Model Editor in the users model and then manually copy settings from the current user to the shared model as described in #4 (it is also possible to manually copy the contents of the Xml column in the ModelDifferenceAspect database table, but this is a much more complicated and advanced task for which we do not provide instructions for).

Future considerations
It is possible to improve the developers' experience, avoid confusion and also reduce support load when this feature is in use.
For instance, it is possible to modify the default XAF project templates to disable storing the Model.XAFML file contents in the database while debugging (see solution #1 above).
A more complicated solution would be always reading the Model.XAFML file, but not storing it in the database, and instead introducing an intermediate model layer whose contents will be stored in the database and are always available for customization from the application UI. See Nate Laff's comment in the S32444 thread for more details on this idea. Technically, it can be done using the CreateCustomModelDifferenceStoreEventArgs .AddExtraDiffStore method when handling the CreateCustomModelDifferenceStore event.

Show previous comments (2)

    Right, that's why I wanted to clarify here. You branched this off of that suggestion I had in which a separate hidden, perhaps in memory (don't really know how all the model diffs work behind the scenes) is created which is always the contents of model.xafml. then any diffs you create, copy, etc… are always applied against it.

      solutions 1 and 2 should be applied together ?

      Dennis Garavsky (DevExpress) 10 years ago

        @M.V.: No, I have updated code comments.
        @Nate: Thanks, Nate.

        Answers approved by DevExpress Support

        created 10 years ago (modified 9 years ago)

        We have implemented the functionality described in this ticket. It will be included in our next update(s).

        Please check back and leave a comment to this response to let us know whether or not this solution addresses your concerns.

        Additional information:

        The latest design-time changes applied in Visual Studio to the Model.xafml file are considered while debugging. To achieve this, the Solution Wizard wraps the ModelDifferenceDbStore initialization in the WinModule.cs and WebModule.cs files to "#if !DEBUG … #endif":

        C#
        private void Application_CreateCustomModelDifferenceStore(Object sender, CreateCustomModelDifferenceStoreEventArgs e) { #if !DEBUG e.Store = new ModelDifferenceDbStore((XafApplication)sender, typeof(ModelDifference), true, "Win"); e.Handled = true; #endif }

        As a result, the FileModelStore is used for the shared Model Differences while debugging. When you first run your application in Release mode, the Model.xafml  file content will be persisted to the database. To enforce the import in the Release mode later, use the Import Shared Model Difference Action.

        This action is not visible by default. To learn how to show it, refer to the How to: Enable the Administrative UI for managing Users' Model Differences article.

          Comments (1)
          DevExpress Support Team 10 years ago

            Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

            Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.