Implement Dependent Reference Properties实现依赖引用属性 (EF)
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 (EF)
- Implement Custom Business Classes and Reference Properties (EF)
- Set a One-to-Many Relationship (EF)
Add a new Manager property of the Contact type to the Contact class. Apply the DataSourceProperty attribute to this property, as shown below.
注意
在继续之前,请花点时间复习以下课程。从业务类库类 (EF) 继承
实现自定义业务类和参考属性 (EF)
设置一对多关系 (EF)
将"联系人"类型的新的"管理器"属性添加到"联系人"类。将 DataSourceProperty 属性应用于此属性,如下所示。
using DevExpress.Persistent.Base;
//...
public class Contact : Person {
public Contact() {
//...
Subordinates = new List<Contact>();
}
//...
[DataSourceProperty("Department.Contacts")]
public virtual Contact Manager { get; set; }
public virtual IList<Contact> Subordinates { get; set; }
}Note
In EF, you always need to implement both "sides" of the relation. This means that each Contact must have a Manager and a list of Subordinates.
With the DataSourceProperty attribute applied, the Manager lookup editor will contain Contact objects that are specified by the Department object's Contacts property.
- 注意
在 EF 中,始终需要实现关系的两个"边"。这意味着每个联系人都必须有一个经理和一个下属列表。
应用 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'")]
public virtual Contact Manager { get; set; }
}With the DataSourceCriteria attribute applied, the Manager lookup editor will contain Contact objects that satisfy the criteria specified in the attribute parameter.
Run the application. Set the Position property to "Manager" for several Contact objects.
应用 DataSourceCriteria 属性后,Manager 查找编辑器将包含满足属性参数中指定的条件的"联系人"对象。
运行应用程序。将"位置"属性设置为多个"联系人"对象的"管理器"。
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。在后一种情况下,需要第三个参数来指定条件。
public class Contact : Person {
//...
[DataSourceProperty("Department.Contacts", DataSourcePropertyIsNullMode.SelectAll)]
[DataSourceCriteria("Position.Title = 'Manager'")]
public virtual Contact Manager { get; set; }
}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.
- 如果未指定"部门"属性,则上述代码将显示"管理器查找"编辑器中的所有联系人。
运行应用程序并检查结果。
You can see the code demonstrated in this lesson in the MySolution.Module | Data | Contact.cs (Contact.vb) file of the EF Demo (Code First) installed with XAF. By default, the EF Demo (Code First) application is installed in %PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\EFDemoCodeFirst.
您可以在 MySolution.模块中看到本课中演示的代码。数据 |Contact.cs(Contact.vb)文件与XAF一起安装的EF演示(代码优先)文件。默认情况下,EF 演示(代码优先)应用程序安装在 %PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\EFDemoCodeFirst中。
Implement Dependent Reference Properties实现依赖引用属性 (EF)的更多相关文章
- Implement Dependent Reference Properties 实现从属引用属性 (XPO)
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 ...
- 【WPF学习笔记】之WPF基础:依赖关系属性和通知
这些天来,对象似乎已经忙得晕头转向了.每个人都希望它们做这做那.Windows® Presentation Foundation (WPF) 应用程序中的典型对象会接到各种各样不同的请求:有要求绑定到 ...
- WPF的依赖项属性
WPF的依赖项属性 属性与事件是.NET抽象模型的核心部分.WPF使用了更高级的依赖项属性(Dependency Property)功能来替换原来.NET的属性,实现了更高效率的保存机制,还添加了附加 ...
- 在 WPF 中获取一个依赖对象的所有依赖项属性
原文:在 WPF 中获取一个依赖对象的所有依赖项属性 本文介绍如何在 WPF 中获取一个依赖对象的所有依赖项属性. 本文内容 通过 WPF 标记获取 通过设计器专用方法获取 通过 WPF 标记获取 p ...
- 如何在 WPF 中获取所有已经显式赋过值的依赖项属性
原文:如何在 WPF 中获取所有已经显式赋过值的依赖项属性 获取 WPF 的依赖项属性的值时,会依照优先级去各个级别获取.这样,无论你什么时候去获取依赖项属性,都至少是有一个有效值的.有什么方法可以获 ...
- Spring -09 -在Spring工程 中加载 properties 文件 -为某个属性添加注解赋初值
1.在src 下新建 xxx.properties 文件,不要任意加空格,注明jdbc等标识名!2.在spring 配置文件中先引入xmlns:context,在下面添加2.1如果需要记载多个配置文件 ...
- WPF中的依赖项属性
Form cnblogs 桂素伟 随着WPF的推广,不得不重新拾起WPF来,因为这块的产品越来越多. 只能跟着MSDN来学了,所以想是在这里记录下学习的过程和对知识的理解. 先从最基本的吧,依赖项属性 ...
随机推荐
- Redis入门(二)-Redis能够做什么
引言 在上篇文章中,我们讲述了Redis的基本知识让读者对Redis有了基本的了解.那么这一节我们就来看一下Redis究竟能做什么. 上一节我们提到了Redis可用作数据库,高速缓存和消息队列代理.这 ...
- JS中的slice()和splice()的区别以及记忆方式
总结 splice()会改变原来的数组,返回的是被改变的内容,比如说通过splice删掉了某一项,那么返回的是删掉的这一项,当然还是会以数组的形式返回. slice不会对原数组进行改变,会返回一个新的 ...
- 项目中使用http referer,为了盗取图片资源
项目背景:因为图片的数据是爬取的别人的图片,而且保存的数据仅仅是图片地址链接,为了减少数据存储和服务器压力,但是这就引发一个问题,有的图片地址没有做防盗处理,可以随意的下载使用:但有些图片的服务器做了 ...
- Android 开发时使用 ViewPager 的问题及解决方案整理
1. ViewPager 的页面重置问题 当我们使用ViewPager控件时,假设我们的ViewPager有三页,当我们第一次启动ViewPager显示第一页的时候,ViewPager会预加载第二页, ...
- dedecmsV5.7 arclist标签同时取出主表和附表里的数据
{dede:arclist}{/dede:arclist}标签默认取出来的是主表x_archives中的数据,如果要取出附表中的数据,需要满足两个条件: 指定channelid属性(注意:channe ...
- 个人的一点小愚见,java有什么优点和缺点
java是一种面向对象的编程语言,优点是可移植性比较高,最初设计时就是本着一次编写到处执行设计的.可以开发各种应用程序和游戏,不过速度没有c++快,所以一般是不用java来编写应用程序和电脑游戏. j ...
- java8-13-默认方法 静态方法 重复注解 类型注解
java8增加默认方法 静态方法 重复注解 类型注解 1.默认方法 default修饰 为什么要有这个特性? 当修改接口时候,需要修改全部实现该接口的类.为了解决这个问题,所以引进默认方法 ...
- win10系统使用小技巧【转】
win10的很多小技巧又简单又实用,这里给大家整理了10个小技巧,一分钟学会,秒变win10高手,看不完的先收藏再看哦. 1.改美区 在设置中时间和语言中将区域和语言改为美国就可以瞬间切换Foreca ...
- txt换行追加写入
with open(negative_txt, 'a') as f: patch_name1 = patch_name + '\n' f.write(patch_name1)
- AcWing 799. 最长连续不重复子序列
网址 https://www.acwing.com/solution/AcWing/content/2069/ 题目描述给定一个长度为n的整数序列,请找出最长的不包含重复数字的连续子序列,输出它的长 ...