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)的更多相关文章

  1. Implement Dependent Reference Properties 实现从属引用属性 (XPO)

    In this lesson, you will learn how to implement properties whose values can depend on other properti ...

  2. 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 ...

  3. 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 ...

  4. 【WPF学习笔记】之WPF基础:依赖关系属性和通知

    这些天来,对象似乎已经忙得晕头转向了.每个人都希望它们做这做那.Windows® Presentation Foundation (WPF) 应用程序中的典型对象会接到各种各样不同的请求:有要求绑定到 ...

  5. WPF的依赖项属性

    WPF的依赖项属性 属性与事件是.NET抽象模型的核心部分.WPF使用了更高级的依赖项属性(Dependency Property)功能来替换原来.NET的属性,实现了更高效率的保存机制,还添加了附加 ...

  6. 在 WPF 中获取一个依赖对象的所有依赖项属性

    原文:在 WPF 中获取一个依赖对象的所有依赖项属性 本文介绍如何在 WPF 中获取一个依赖对象的所有依赖项属性. 本文内容 通过 WPF 标记获取 通过设计器专用方法获取 通过 WPF 标记获取 p ...

  7. 如何在 WPF 中获取所有已经显式赋过值的依赖项属性

    原文:如何在 WPF 中获取所有已经显式赋过值的依赖项属性 获取 WPF 的依赖项属性的值时,会依照优先级去各个级别获取.这样,无论你什么时候去获取依赖项属性,都至少是有一个有效值的.有什么方法可以获 ...

  8. Spring -09 -在Spring工程 中加载 properties 文件 -为某个属性添加注解赋初值

    1.在src 下新建 xxx.properties 文件,不要任意加空格,注明jdbc等标识名!2.在spring 配置文件中先引入xmlns:context,在下面添加2.1如果需要记载多个配置文件 ...

  9. WPF中的依赖项属性

    Form cnblogs 桂素伟 随着WPF的推广,不得不重新拾起WPF来,因为这块的产品越来越多. 只能跟着MSDN来学了,所以想是在这里记录下学习的过程和对知识的理解. 先从最基本的吧,依赖项属性 ...

随机推荐

  1. App 自动化框架设计思路

    最近在整理和学习Appium+Java 自动化框架,对APP自动化框架的部分设想参考了一些文章,先进行整理下: 框架的思路一: 思考引入:https://www.cnblogs.com/yunfeio ...

  2. C#二位数组 数组矩阵对角线之和

    二维数组: public static void Main(string[] args) { int[,] a = new int[3, 3]; Random rom = new Random(); ...

  3. 剑指offer笔记面试题9----用两个栈实现队列

    题目:用两个栈实现一个队列.队列的声明如下,请实现它的两个函数appendTail和deleteHead,分别完成在尾部插入节点和在队列头部删除节点的功能. 测试用例: 往空的队列里添加.删除元素. ...

  4. C#关于反序列化实例时,接收实体字段少于或大于原实体对象 解析测试

    在项目中总会用到son解析,比如RabbitMQ中使用json串解析,比如发过来的实体对象有50个字段,而实际只需要用到里面的几个字段,这时我们创建实体时,只需要创建需要的几个字段即可. 测试实例,首 ...

  5. php number_format金钱 价格 格式处理 由分单位转换成元(保留2为小数)

    /** * priceFormat * 价格格式处理 * * @access public * @param null * @since 1.0 * @return object */ if(!fun ...

  6. 《数据挖掘导论》实验课——实验一、数据处理之Numpy

    实验一.数据处理之Numpy 一.实验目的 1. 了解numpy库的基本功能 2. 掌握Numpy库的对数组的操作与运算 二.实验工具: 1. Anaconda 2. Numpy 三.Numpy简介 ...

  7. es6 Iterator和for...of循环

    javascript表示集合的数据结构有 es5: array object es6: map set, 一共4种数据集合 需要一种统一的接口机制来处理所有不同的数据结构 遍历器就是这样一种机制,它是 ...

  8. 【使用篇二】SpringBoot使用JdbcTemplate操作数据库(12)

    Spring对数据库的操作在jdbc上面做了深层次的封装,提供了JdbcTemplate模板. 在SpringBoot使用JdbcTemplate很简单: 引入数据库驱动包(mysql或oracle) ...

  9. Rust v1.39发布 - 这个编程语言真不一般!

    https://zhuanlan.zhihu.com/p/90612241 今天(2019-11-07)Rust终于发布了期待已久的v1.39版本,增加了重量级的async/await关键字支持.Ru ...

  10. WPF 委托 事件 B窗体调用A窗体方法

    原文:WPF 委托 事件 B窗体调用A窗体方法 具体实现 A窗体 中加载B窗体  B窗体触发A窗体里的方法 当点击B窗体确定Button事件   给A窗体俩个TextBox赋值 并关闭B窗体 B窗体 ...