Implement Dependent Reference Properties 实现从属引用属性 (XPO)
In this lesson, you will learn how to implement properties whose values can depend on other properties. The Manager property will be added to the Contact class. By default, it will be represented by a lookup editor containing all Contacts that exist in the database. However, you may need this editor to contain Contacts from the same Department. In addition, you may need the Position of these Contacts to be "Manager". To do this, use the DataSourcePropertyAttribute and DataSourceCriteriaAttribute attributes for the Manager property.
在本课中,您将学习如何实现其值可以依赖于其他属性的属性。"管理器"属性将添加到"联系人"类中。默认情况下,它将由包含数据库中存在的所有联系人的查找编辑器表示。但是,您可能需要此编辑器包含来自同一部门的联系人。此外,您可能需要这些联系人的位置是"经理"。为此,请使用 Manager 属性的 DataSourceProperty 属性和数据源标准属性属性。
Note注意
Before proceeding, take a moment to review the following lessons.
- Inherit from the Business Class Library Class (XPO)
- Implement Custom Business Classes and Reference Properties (XPO)
- Set a One-to-Many Relationship (XPO)
在继续之前,请花点时间复习以下课程。
- 从商务舱库类 (XPO) 继承
- 实现自定义业务类和参考属性 (XPO)
- 设置一对多关系 (XPO)
Add a new Manager property of the Contact type to the Contact class. Apply the DataSourceProperty attribute to this property, as shown below.
将"联系人"类型的新的"管理器"属性添加到"联系人"类。将 DataSourceProperty 属性应用于此属性,如下所示。
[DefaultClassOptions]
public class Contact : Person {
//...
private Contact manager;
[DataSourceProperty("Department.Contacts")]
public Contact Manager {
get { return manager; }
set { SetPropertyValue(nameof(Manager), ref manager, value); }
}
//...
}
- With the DataSourceProperty attribute applied, the Manager lookup editor will contain Contact objects that are specified by the Department object's Contacts property.
- 应用 DataSourceProperty 属性后,Manager 查找编辑器将包含由"部门"对象的"联系人"属性指定的联系人对象。
Run the application and select Contact in the drop-down list of the New combo box. The Contact Detail View will be invoked. Specify the Department property and expand the Manager lookup editor. Make sure that the Department property of the listed objects is the same as those you specified above.
运行该应用程序,并在"新建组合"框的下拉列表中选择"联系人"。将调用"联系人详细信息"视图。指定"部门"属性并展开"管理器查找"编辑器。确保列出的对象的"部门"属性与您上面指定的对象相同。

Apply the DataSourceCriteria attribute to the Contact class' Manager property as shown below.
- 将"数据源标准"属性应用于联系人类的管理器属性,如下所示。
public class Contact : Person {
//...
[DataSourceProperty("Department.Contacts")]
[DataSourceCriteria("Position.Title = 'Manager' AND Oid != '@This.Oid'")]
public Contact Manager {
// ...
}
// ...
}
- With the DataSourceCriteria attribute applied, the Manager lookup editor will contain Contact objects that satisfy the criteria specified in the attribute parameter.
- 应用 DataSourceCriteria 属性后,Manager 查找编辑器将包含满足属性参数中指定的条件的"联系人"对象。
Run the application. Set the Position property to "Manager" for several Contact objects.
运行应用程序。将"位置"属性设置为多个"联系人"对象的"管理器"。

Select Contact in the New (
) button's drop-down list. The Contact Detail View will be invoked. Specify the Department property and expand the Manager lookup editor. Check to make sure that the Position property is set to "Manager" for each of the listed objects.在"新建(new_dropdown_btn)"按钮的下拉列表中选择"联系人"。将调用"联系人详细信息"视图。指定"部门"属性并展开"管理器查找"编辑器。检查以确保每个列出的对象的"位置"属性设置为"管理器"。

If the Department property is not specified for a Contact, you can provide another data source for the Manager lookup editor. To do this, specify the second parameter for the DataSourceProperty attribute. In the code below, this parameter is set to the DataSourcePropertyIsNullMode.SelectAll value. You can also set the DataSourcePropertyIsNullMode.SelectNothing or DataSourcePropertyIsNullMode.CustomCriteria values. In the latter case, a third parameter is required to specify a criterion.
如果未为联系人指定"部门"属性,则可以为 Manager 查找编辑器提供其他数据源。为此,请为 DataSourceProperty 属性指定第二个参数。在下面的代码中,此参数设置为 DataSourcePropertyIsNullMode。您还可以设置"数据源属性"NullMode。在后一种情况下,需要第三个参数来指定条件。
[DefaultClassOptions]
public class Contact : Person {
//...
[DataSourceProperty("Department.Contacts",DataSourcePropertyIsNullMode.SelectAll)]
[DataSourceCriteria("Position.Title = 'Manager' AND Oid != '@This.Oid'")]
public Contact Manager {
// ...
}
// ...
}
- The code above will show all contacts in the Manager lookup editor, if the Department property is not specified.
- Run the application and check the results.
- 如果未指定"部门"属性,则上述代码将显示"管理器查找"编辑器中的所有联系人。
- 运行应用程序并检查结果。
Note
You can implement the same behavior at design time. For details, refer to the Filter Lookup Editor Data Source lesson.
注意
您可以在设计时实现相同的行为。有关详细信息,请参阅筛选器查找编辑器数据源课程。
You can see the code demonstrated here in the MySolution.Module | Business Objects | Contact.cs (Contact.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.模块 |业务对象 |Contact.cs (Contact.vb) 文件的主演示安装与 XAF.主演示应用程序安装在%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/
.
Implement Dependent Reference Properties 实现从属引用属性 (XPO)的更多相关文章
- Implement Dependent Reference Properties实现依赖引用属性 (EF)
In this lesson, you will learn how to implement properties whose values can depend on other properti ...
- Implement Custom Business Classes and Reference Properties 实现自定义业务类和引用属性(XPO)
In this lesson, you will learn how to implement business classes from scratch. For this purpose, the ...
- Implement Custom Business Classes and Reference Properties实现自定义业务类和引用属性(EF)
In this lesson, you will learn how to implement business classes from scratch. For this purpose, the ...
- Spring -09 -在Spring工程 中加载 properties 文件 -为某个属性添加注解赋初值
1.在src 下新建 xxx.properties 文件,不要任意加空格,注明jdbc等标识名!2.在spring 配置文件中先引入xmlns:context,在下面添加2.1如果需要记载多个配置文件 ...
- Java的properties文件读取和属性修改
package Test; import java.io.BufferedInputStream;import java.io.FileInputStream;import java.io.FileO ...
- 如何快速获取properties中的配置属性值
本文为博主原创,未经博主允许,不得转载: 在项目中,经常需要将一些配置的常量信息放到properties文件中,这样在项目的配置变动的时候,只需要修改配置文件中 对应的配置常量即可. 在项目应用中,如 ...
- java读写properties配置文件不改变属性的顺序和注释
先贴代码 import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java ...
- 使用 application.properties 中配置的属性,举例:@Value("${server.port}")
使用 application.properties 中配置的属性:@Value 注解. @RestController public class HelloWorldController { @Val ...
- java获取properties配置文件中某个属性最简单方法
假如我想获取src目录下sysConfig.properties中的uploadpath属性的值 方法如下所示: private static final ResourceBundle bundle ...
随机推荐
- 视频剪辑什么鬼?Python 带你高效创作短视频
阅读文本大概需要 10 分钟. 近两年,抖音.快手将短视频推到风口浪尖上,要生产出高质量的视频,离不开视频剪辑这一环节:在全民剪片浪潮中,大众使用最多的剪辑软件如:Pr.FCPX.剪印.Vue 等. ...
- Mbp,一个用于学习.net core的开发框架
Mbp(https://github.com/mbpframework/Mbp)是一个.net core 3的企业级web开发框架,是我个人用于学习.net core而发起的一个开源项目.这个借鉴了国 ...
- .Net Core控制台&EFCore连接Mysql
在用惯了Asp.Net Core提供的基架后,反过来想一想,貌似忘记了控制台如何去连接数据库了,因此,写一篇文章来借此巩固下并以后再来回顾时,加快步骤. 1.新建一个.Net Core控制台,然后安装 ...
- springboot windows10风格 activiti 整合项目框架源码 shiro 安全框架 druid
官网:www.fhadmin.org 此项目为Springboot工作流版本 windows 风格,浏览器访问操作使用,非桌面应用程序. 1.代码生成器: [正反双向](单表.主表.明细表.树形表 ...
- wx-一个简单页面
一个具有顶部,底部和中间的html页面,但没有js <view class="root"> <!-- 标签栏的页签 固定高度 --> <view cl ...
- 医院信息集成平台(ESB)数据集成建设方案
一.数据资产目录建设 依据卫生部信息化工作领导小组办公室卫生部统计信息中心2011年3月发布的<基于电子病历的医院信息平台建设技术解决方案——业务部分>. 临床服务域 包含12个二级类目: ...
- zuul网关
Zuul路由网关简介及基本使用 简介 Zuul API路由网关服务简介 请看上图,这里的API 路由网关服务 由Zuul实现,主要就是对外提供服务接口的时候,起到了请求的路由和过滤作用,也因此能够隐藏 ...
- Git实战指南----跟着haibiscuit学Git(第九篇)
笔名: haibiscuit 博客园: https://www.cnblogs.com/haibiscuit/ Git地址: https://github.com/haibiscuit?tab=re ...
- SAP QM 检验批里某检验特性的取样数量跟检验计划设置不符?
SAP QM 检验批里某检验特性的取样数量跟检验计划设置不符? 如下检验批号 890000045939, 结果录入界面,第二个特性里,取样数量是50个.实际上,该检验批对应的检验计划里, 采样过程L- ...
- 字段明明存在,用Web API使用该字段进行查询报错?
我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面 ...