XAF-内置初始化数据 (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.
-
打开位于 MySolution.模块项目的数据库更新文件夹中的Updater.cs(Updater.vb)文件。将以下代码添加到模块更新器.更新数据库后更新架构方法。
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 = "tellitson@example.com"; 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.
-
添加上述代码后,如果联系人对象不存在,将在应用程序数据库中创建该对象。
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.
-
每次运行应用程序时,它都会将应用程序版本与数据库版本进行比较,并在应用程序或数据库中查找更改。如果数据库版本低于应用程序版本,则应用程序将引发 XafApplication.DatabaseVersion 不匹配事件。
-
此事件由 WinForms 处理,并在解决方案模板中ASP.NET应用程序。
-
当应用程序在调试模式下运行时,此事件处理程序使用内置的数据库更新程序来更新应用程序的数据库。更新数据库架构后,将调用模块更新器.Updatedatabase 后更新架构方法。在此方法中,可以将所需的业务对象保存到数据库中。
-
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).
-
如上述代码所示,eXpressApp 框架 (XAF) 使用对象空间对象操作持久对象(请参阅创建、读取、更新和删除数据)
-
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.
- 要指定在 BaseObjectSpace.FindObject 方法调用中作为参数传递的条件,将使用条件运算符。其 CriteriaOperator.Parse 方法转换字符串,将条件表达式指定为其条件运算符等效项。要了解有关如何指定条件的详细信息,请参阅生成条件的方法主题。
- 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.
-
运行 WinForms 或ASP.NET应用程序。选择导航控件中的"联系人"项。请注意,新的联系人"玛丽·特利森"出现在右侧的列表中。
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/
您可以在 MySolution.模块中查看本教程的代码。数据库更新 |Updater.cs (Updater.vb) 文件的主演示安装与 XAF.默认情况下,主演示应用程序安装在%PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\MainDemo 中。ASP.NET版本可在 http://demos.devexpress.com/XAF/MainDemo/ 在线获取
.
XAF开发成品案例参考
如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。
作者博客: http://www.cnblogs.com/foreachlife
欢迎加入CIIP框架\XAF技术应用交流群: 336090194 群文件中有更多相关工具及文档资料
转载请注明出处。多谢!
欢迎加我微信: admiralcn 或扫码:
![](http://files.cnblogs.com/files/foreachlife/wx.bmp)