Supply Initial Data提供初始数据 (EF)
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(, , );
}
//...
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应用程序。选择导航控件中的"联系人"项。请注意,新的联系人"玛丽·特利森"出现在右侧的列表中。
Note
Note that in the Inherit from the Business Class Library Class (EF) lesson, the database initializer was set to clear the database in case the business model changes. This means that all objects created at runtime will be deleted after the next change in the business model. It is recommended that you use the approach described in this lesson to create all objects required for testing purposes. They will persist in your application regardless of the database.
注意
请注意,在从 Business 类库类 (EF) 继承一课中,数据库初始化程序已设置为清除数据库,以防业务模型发生更改。这意味着在运行时创建的所有对象都将在业务模型中的下一次更改后删除。建议您使用本课中描述的方法创建测试所需的所有对象。无论数据库如何,它们都将保留在应用程序中。
You can see the code for this tutorial in the EFDemo.Module | Database Update | Updater.cs (Updater.vb) file of the EF Demo (Code First) demo installed with XAF. By default, the EF Demo (Code First) application is installed in %PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\EFDemoCodeFirst.
您可以在 EFDemo.模块中查看本教程的代码。数据库更新 |Updater.cs (Updater.vb) 文件 EF 演示(代码优先)演示安装与 XAF。默认情况下,EF 演示(代码优先)应用程序安装在 %PUBLIC%_文档_DevExpress 演示 19.2_组件_eXpressApp 框架_EFDemoCodeFirst 中。
Supply Initial Data提供初始数据 (EF)的更多相关文章
- How to: Supply Initial Data for the Entity Framework Data Model 如何:为EF数据模型提供初始数据
After you have introduced a data model, you may need to have the application populate the database w ...
- Define the Data Model and Set the Initial Data 定义数据模型并设置初始数据
This topic describes how to define the business model and the business logic for WinForms and ASP.NE ...
- 18.翻译系列:EF 6 Code-First 中的Seed Data(种子数据或原始测试数据)【EF 6 Code-First系列】
原文链接:https://www.entityframeworktutorial.net/code-first/seed-database-in-code-first.aspx EF 6 Code-F ...
- Salesforce Integration 概览(四) Batch Data Synchronization(批量数据的同步)
本篇参考:https://resources.docs.salesforce.com/sfdc/pdf/integration_patterns_and_practices.pdf 前两篇博客讲了一下 ...
- CSharpGL(38)带初始数据创建Vertex Buffer Object的情形汇总
CSharpGL(38)带初始数据创建Vertex Buffer Object的情形汇总 开始 总的来说,OpenGL应用开发者会遇到为如下三种数据创建Vertex Buffer Object的情形: ...
- Dojo Data Store——统一数据访问接口
原文地址:http://www.infoq.com/cn/articles/wq-dojo-data-store 无论在传统的桌面应用还是在主流的互联网应用中,数据始终占据着软件应用中的核心地位.当下 ...
- 使用 DB Fixtures 为 Unit Test 提供基础数据,Sails + Mocha 实现。
使用 DB Fixtures 为 Unit Test 提供基础数据,Sails + Mocha 实现. 问题:Test Fixture 太分散,管理麻烦. 在做单元测试的时候,数据回滚是个比较麻烦的问 ...
- SAS DATA步读取数据
上面一节讲了SAS的基本概念,以及语法结构,这次主要讲解SAS DATA步读取数据. 1 ·列表输入 2 ·按列输入 3 ·格式化输入 使用DATA步读取数据的基本形式如下: DA ...
- 微信小程序,关于设置data里面的数据。
关于设置 data里面的数据 wxml: <view>{{userName}}</view> data: { userName:'张三', } 有两种方法 方法一:直接使用点关 ...
随机推荐
- 百万级高并发mongodb集群性能数十倍提升优化实践
背景 线上某集群峰值TPS超过100万/秒左右(主要为写流量,读流量很低),峰值tps几乎已经到达集群上限,同时平均时延也超过100ms,随着读写流量的进一步增加,时延抖动严重影响业务可用性.该集群采 ...
- WinForm自定义控件之DefaultValue的误解
DefaultValue,顾名思义,默认值的意思.但这个默认值不是用来显示的,它的作用是当属性设置的值(无法代码写还是属性窗口输入)与DefaultValue相同时,会区别显示,比如其它值加粗,Def ...
- Cesium 限制相机进入地下
有时我们在Cesium操作时,点击鼠标中间滚轮可更改视角,有时会使相机进入地下,导致体验很差,网上说了很多中方法,效果都不好或者没效果,下面是我翻了源码找到的方法,亲测有效.如有问题可按照专栏上的联系 ...
- 升级sharepoint2013遇到的坑
现在要将sharepoint2010,ProjectServer2010升级到2016的版本,需要先升级到2013的版本. 按照官方文档,瞎搞将sharepoint2010升级到2013的版本,中间出 ...
- iOS核心动画高级技巧-4
8. 显式动画 显式动画 如果想让事情变得顺利,只有靠自己 -- 夏尔·纪尧姆 上一章介绍了隐式动画的概念.隐式动画是在iOS平台创建动态用户界面的一种直接方式,也是UIKit动画机制的基础,不过它并 ...
- Linux-3.14.12内存管理笔记【伙伴管理算法(4)】
此处承接前面未深入分析的页面释放部分,主要详细分析伙伴管理算法中页面释放的实现.页面释放的函数入口是__free_page(),其实则是一个宏定义. 具体实现: [file:/include/linu ...
- weblogic启动节点服务java.lang.ClassCastException:com.octestring.vde.backend.BackendRoot cannot be cast to com.octestring.vde.backend.standard.BackendStandard类型转换异常
weblogic启动节点服务器报错,java.lang.ClassCastException:com.octestring.vde.backend.BackendRoot cannot be cast ...
- Mysql - 高可用方案之MM+Keepalived
一.概述 本文将介绍mysql的MM+Keepalived方案.该方案由两个mysql服务器组成,这两个mysql互为主备.其中一台主作为写服务器,另一台主作为读服务器.通过keepalived软件管 ...
- ASP.NET Core gRPC 健康检查的实现方式
一. 前言 gRPC 服务实现健康检查有两种方式,前面在此文 ASP.NET Core gRPC 使用 Consul 服务注册发现 中有提到过,这里归纳整理一下.gRPC 的健康检查,官方是定义了标准 ...
- WPF 3D 球面导览
基于WPF的3D Sphere实现模式,升级实现了该3D导览Demo.先pose一张demo效果图 所有顶点的坐标来源于足球的顶点.足球整个球面完全由正五边形和正六边形拼成,每条拼缝的长度一致,故知道 ...