In this lesson, you will learn how to set a one-to-many relationship between business objects. The Contact and Department business objects will be related by a one-to-many relationship. For this purpose, the Contacts property will be added to the Department class representing the "Many" part of the relationship. You will then learn the basics of automatic user interface construction for referenced objects.

在本课中,您将学习如何设置业务对象之间的一对多关系。联系人和部门业务对象将通过一对多关系关联。为此,联系人属性将添加到表示关系的"许多"部分的"部门"类中。然后,您将学习引用对象的自动用户界面构造的基础知识。许多关系 (XPO)

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 Many-to-Many Relationship (XPO)
  • To implement the "One" part of the Department-Contacts relationship, decorate the Contact class' Department property with the AssociationAttribute.

  • 从商务舱库类 (XPO) 继承

  • 实现自定义业务类和参考属性 (XPO)

  • 设置多对多关系 (XPO)

  • 要实现部门-联系人关系的"One"部分,请使用"关联属性"装饰联系人类的部门属性。

     
    [DefaultClassOptions]
    public class Contact : Person {
    //...
    private Department department;
    [Association("Department-Contacts")]
    public Department Department {
    get {return department;}
    set {SetPropertyValue(nameof(Department), ref department, value);}
    }
    //...
    }

    For information on the Association attribute, refer to the Set a Many-to-Many Relationship (XPO) lesson.

有关关联属性的信息,请参阅设置多对多关系 (XPO) 课程。

  • To implement the "Many" part of the Department-Contacts relationship, add the Contacts property to the Department class and decorate this property with the Association attribute.

  • 要实现部门-联系人关系的"许多"部分,将"联系人"属性添加到"部门"类,并使用"关联"属性装饰此属性。

    public class Department : BaseObject {
    //...
    [Association("Department-Contacts")]
    public XPCollection<Contact> Contacts {
    get {
    return GetCollection<Contact>(nameof(Contacts));
    }
    }
    }
    Note

    If you have CodeRush

    注意
    如果您有代码 CodeRush

  • installed, you can use Code Templates when implementing business classes. Using Code Templates decreases code creation time, because it helps avoid having to type the entire code manually and allows you to create regular code sections with only a few keystrokes. To learn about the built-in Code Templates for eXpress Persistent Objects, refer to the XPO and XAF Templates topic.

  • Run the WinForms or ASP.NET application. Invoke a Detail View for a Department object (see the previous lesson “Set a Many-to-Many Relationship (XPO)”). You can see the Contacts group. To add objects to the Contacts collection, use the New () or Link () buttons in this tab. The Link button allows for the adding of references to existing Contact objects.

  • 在实现业务类时,可以使用代码模板。使用代码模板可缩短代码创建时间,因为它有助于避免手动键入整个代码,并允许您只需几个击键即可创建常规代码部分。要了解 eXpress 持久对象的内置代码模板,请参阅 XPO 和 XAF 模板主题。
  • 运行 WinForms 或ASP.NET应用程序。调用部门对象的详细信息视图(请参阅上一课"设置多对多关系 (XPO)")。您可以看到"联系人"组。要将对象添加到"联系人"集合,请使用此选项卡中的"新建(button_new)"或"链接(link_btn)"按钮。"链接"按钮允许添加对现有联系人对象的引用。

    To remove a reference to an object from this collection, use the Unlink () button.

要从此集合中删除对对象的引用,请使用"取消链接(unlink_img)"按钮。

Tip

提示

If you create a new Department and then create a new Contact in the Contacts collection, an associated Department is not immediately visible in the Detail View of the newly created Contact. The link between these objects is added later, when you save the Contact. You can change this behavior using the XafApplication.LinkNewObjectToParentImmediately property. When it is set to true, the link will be created and saved immediately after you click New.

如果创建新的"部门",然后在"联系人"集合中创建新的"联系人",则关联部门不会立即在新创建的"联系人"的"详细信息"视图中显示。保存联系人时,稍后将添加这些对象之间的链接。您可以使用 XafApplication.LinkNewObjectParentParent立即属性更改此行为。设置为 true 时,链接将在单击"新建"后立即创建并保存。

You can see the code demonstrated in this lesson 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%_文档_DevExpress 演示 19.2_组件_eXpressApp 框架_MainDemo 中。ASP.NET版本可在 http://demos.devexpress.com/XAF/MainDemo/ 在线获取

.

.

Set a One-to-Many Relationship设置一对多关系 (XPO)的更多相关文章

  1. Set a One-to-Many Relationship设置一对多关系 (EF)

    In this lesson, you will learn how to set a one-to-many relationship between business objects. The C ...

  2. Set a Many-to-Many Relationship设置多对多关系 (EF)

    In this lesson, you will learn how to set relationships between business objects. For this purpose, ...

  3. 一对多关系domain Model中设置使用AutoMapper时出错

    在使用AutoMapper时,把数据从VO-PO时显示如下错误,错误提示说在一对多关系中已将集合设置为EntityCollection,那么这个是为什么呢. 看下action中的代码,我们可以发现这是 ...

  4. Dynamic CRM一对多关系的数据删除时设置自动删除关联的数据

    在业务实体中主子表非常常见,然后子表可能有会有自己的子表或者多对多关系,在删除的业务场景下,删除主数据,剩余的子数据就成了脏数据, 之前的做法是,监听主表的删除事件,然后在插件中找到其下的子表数据然后 ...

  5. [Fluent NHibernate]一对多关系处理

    目录 写在前面 系列文章 一对多关系 总结 写在前面 上篇文章简单介绍了,Fluent Nhibernate使用代码的方式生成Nhibernate的配置文件,以及如何生成持久化类的映射文件.通过上篇的 ...

  6. EF Code First中的主外键约定和一对一、一对多关系的实现

    对于主外键约定的理解,其实是学习实体间一对一和一对多关系的基础. 1.1 主键(Key)约定 主键的默认约定是:只要字段名为--实体名(类名)+"id"(不区分大小写),这就算是默 ...

  7. 10.Configure One-to-Many(配置一对多关系)【Code-First系列】

    现在,我们将学习怎么配置一对多的关系. Visit Entity Relationship section to understand how EF manages one-to-one, one-t ...

  8. [NHibernate]一对多关系(级联删除,级联添加)

    目录 写在前面 文档与系列文章 一对多关系 一个例子 级联删除 级联保存 总结 写在前面 在前面的文章中,我们只使用了一个Customer类进行举例,而在客户.订单.产品中它们的关系,咱们并没有涉及, ...

  9. [NHibernate]一对多关系(关联查询)

    目录 写在前面 文档与系列文章 一对多查询 总结 写在前面 上篇文章介绍了nhibernate的一对多关系如何配置,以及级联删除,级联添加数据的内容.这篇文章我们将学习nhibernate中的一对多关 ...

随机推荐

  1. [C++]Game模板-正面视角

    前言 本来是想打一个小游戏的-- 可是打到一半思路断了-- 只打出了模板--先把模板拿出来放着 Code //head #include <iostream> #include <c ...

  2. 痞子衡嵌入式:飞思卡尔i.MX RTyyyy系列MCU特性那些事(2)- RT1052DVL6性能实测(CoreMark)

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是飞思卡尔i.MX RTyyyy系列MCU的性能. 在前面的文章 i.MXRTyyyy微控制器概览 里,痞子衡给大家简介过恩智浦半导体在2 ...

  3. [Spring cloud 一步步实现广告系统] 10. 使用Ribbon 实现微服务调用

    在使用Ribbon调用广告投放系统API之前,我们需要先创建2个VO对象,AdPlanVO,AdPlanGetRequestVO. //数据请求对象 @Data @NoArgsConstructor ...

  4. JS MD5 返回二进制格式

    今天靠大佬的帮助,成功的解决了一个弄了好久的问题.起因就是我们要对一个手机号进行加密. 加密方式是把一个字符串进行MD5加密之后,得到原始 16 字符二进制格式.然后把得到的这个字符作为AES的key ...

  5. ie11 SCRIPT5011:不能执行已释放Script的代码

    依照我遇到的问题为例: (我的页面结构为:父页面中嵌套有iframe子页面) 1.造成这种情况的原因是:父页面初始化声明变量a为数组(数组对象是引用类型,赋值传递的是地址),创建iframe子页面后给 ...

  6. Windows应急日志常用的几个事件ID

    Windows应急日志常用的几个事件ID点击站内没有搜索到,可能搜索姿势不对,发一下吧,应急时可能会用到,根据日志时间点判断入侵 日志路径:C:\Windows\System32\winevt\Log ...

  7. leaflet 结合 d3.js 实现 geojson 数据地形剖面分析(附源码下载)

    前言 leaflet 入门开发系列环境知识点了解: leaflet api文档介绍,详细介绍 leaflet 每个类的函数以及属性等等 leaflet 在线例子 leaflet 插件,leaflet ...

  8. SAP depreciation key config

    正常折旧 Configure 1.分配总帐科目 spro进入后台配置 –> Financial Accounting(New) –> Asset Accounting –> Depr ...

  9. Python numpy tensorflow 中的 点乘 和 矩阵乘法

    1)点乘(即“ * ”) ---- 各个矩阵对应元素做乘法  若 w 为 m*1 的矩阵,x 为 m*n 的矩阵,那么通过点乘结果就会得到一个 m*n 的矩阵. 若 w 为 m*n 的矩阵,x 为 m ...

  10. Python语法速查: 4. 字符串常用操作

    返回目录 (1)字符串常用方法 Python3中,字符串全都用Unicode形式,所以省去了很多以前各种转换与声明的麻烦.字符串属于序列,所有序列可用的方法(比如切片等)都可用于字符串. 注意:字符串 ...