XAF- built initialization data (XPO)

  • Open the Updater.cs (Updater.vb) file, located in the MySolution.Module project's Database Update folder. Add the following code to the ModuleUpdater.UpdateDatabaseAfterUpdateSchema method.

  • Open the MySolution. Module project database update folder Updater.cs (Updater.vb) files. Add the following code module updater to update the database schema methods after update.

using MySolution.Module.BusinessObjects;
//...

public class Updater : DevExpress.ExpressApp.Updating.ModuleUpdater {
    //...
        public override void UpdateDatabaseAfterUpdateSchema() {
        base.UpdateDatabaseAfterUpdateSchema();

        Contact contactMary = ObjectSpace.FindObject<Contact>(
            CriteriaOperator.Parse("FirstName == 'Mary' && LastName == 'Tellitson'"));
        if (contactMary == null) {
            contactMary = ObjectSpace.CreateObject<Contact>();
            contactMary.FirstName = "Mary";
            contactMary.LastName = "Tellitson";
            contactMary.Email = "[email protected]";
            contactMary.Birthday = new DateTime(1980, 11, 27);
        }
        //...
        ObjectSpace.CommitChanges();
    }
}

 

  • After adding the code above, the Contact object will be created in the application database, if it does not already exist.

  • After adding the above code, if the contact object does not exist, the object will be created in the application database.

    Each time you run the application, it compares the application version with the database version and finds changes in the application or database. If the database version is lower than the application version, the application raises the XafApplication.DatabaseVersionMismatch event. This event is handled by the WinForms and ASP.NET applications in a solution template. When the application runs in debug mode, this event handler uses the built-in Database Updater to update the application's database. After the database schema is updated, the ModuleUpdater.UpdateDatabaseAfterUpdateSchema method is called. In this method, you can save the required business objects to the database.

  • Each time you run the application, it will be the version of the application and the database version are compared, and look for changes in the application or database. If the database version is lower than the version of the application, the application will lead to XafApplication.DatabaseVersion not match the event.

  • This event is handled by WinForms, and solution templates in ASP.NET applications.

  • When the application is running in debug mode, this event handler uses the built-in database program to update the database application. After updating the database schema, calls the update module updates the architectural approach after .Updatedatabase. In this method, you can save the required business objects to the database.

 

  • As you can see in the code above, eXpressApp Framework (XAF) uses an Object Space object to manipulate persistent objects (see Create, Read, Update and Delete Data).

  • As shown in the above code, eXpressApp frame (XAF) using object space object operation persistent objects (see create, read, update and delete data) 

  • To specify the criteria passed as a parameter in the BaseObjectSpace.FindObject method call, the CriteriaOperator is used. Its CriteriaOperator.Parse method converts a string, specifying a criteria expression to its CriteriaOperator equivalent. To learn more on how to specify criteria, refer to the Ways to Build Criteria topic.

  • To specify conditions in BaseObjectSpace.FindObject passed as a parameter in the method call, using the conditional operator. Which CriteriaOperator.Parse method of converting a string of conditional expression for the condition operator specified equivalent. To learn more about how to specify conditions, see the topic generated method conditions. 
  • Run the WinForms or ASP.NET application. Select the Contact item in the navigation control. Notice that the new contact, "Mary Tellitson", appears in the list to the right.
  • Run WinForms or ASP.NET applications. Select the navigation controls in the "Contact" item. Please note, new contact "Mary Teli Sen" appears in the list on the right.

    Tutorial_BMD_Lesson2_5_1

You can see the code for this tutorial in the MySolution.Module | Database Update | Updater.cs (Updater.vb) file of the Main Demo installed with XAF. The MainDemo application is installed in %PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\MainDemo by default. The ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/

You can view the code in this tutorial MySolution. Module. Database Update | Main demo installation and XAF Updater.cs (Updater.vb) files by default, the main demo application installed. % The PUBLIC% \ Documents \ DevExpress the Demos  19.2 \ Components \ eXpressApp Framework \ MainDemo in. ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/

.

Guess you like

Origin www.cnblogs.com/foreachlife/p/SupplyInitialData.html