In this lesson, you will learn how to set relationships between business objects. For this purpose, the Task business class will be implemented and a Many-to-Many relationship will be set between the Contact and Task objects. You will also learn the basics of automatic user interface construction for the referenced objects.

在本课中,您将学习如何设置业务对象之间的关系。为此,将实现 Task 业务类,并在"联系人"和"任务"对象之间设置多对多关系。您还将学习引用对象的自动用户界面构造基础知识。

  • To add the Task business class to the application, you can use the Task class from the Business Class Library. Since you need to set a relationship between the Contact and Task objects, you need to customize the Task class implementation. Inherit from this class and add the Contacts collection property, as shown in the following code.

  • 要将 Task 业务类添加到应用程序,可以使用 Business 类库中的"任务"类。由于您需要设置"联系人"和"任务"对象之间的关系,因此需要自定义 Task 类实现。从此类继承并添加"联系人"集合属性,如以下代码所示。

     
    using DevExpress.ExpressApp.Model;
    // ...
    [DefaultClassOptions]
    [ModelDefault("Caption", "Task")]
    public class DemoTask : Task {
    public DemoTask(Session session): base(session) { }
    [Association("Contact-DemoTask")]
    public XPCollection<Contact> Contacts {
    get {
    return GetCollection<Contact>(nameof(Contacts));
    }
    }
    }
    Important

    Do not modify the XPCollection property declaration demonstrated above. Manipulating the collection or introducing any additional settings within the declaration may cause unpredictable behavior.

    重要
    不要修改上面演示的 XPCollection 属性声明。操作集合或在声明中引入任何其他设置可能会导致不可预知的行为。

    In this code, the AssociationAttribute is applied to the XPCollection type Contacts property, representing the collection of associated Contacts. The Association attribute is required when setting a relationship between objects. Note that the Contacts property getter implementation - the GetCollection method - is used to return a collection.

在此代码中,关联属性应用于 XPCollection 类型"联系人"属性,表示关联联系人的集合。设置对象之间的关系时,需要关联属性。请注意,联系人属性 getter 实现 - GetCollection 方法 - 用于返回集合。

Note

The ModelDefaultAttribute attribute, which is applied to the DemoTask class, specifies the "Task" value for the Caption property of the Application Model's BOModel | DemoTask node. Generally, you can specify any property of the Application Model's BOModel | <Class> or BOModel | <Class> | OwnMembers | <Member> node, by applying the ModelDefault attribute to a business class or its member.

注意
应用于 DemoTask 类的模型默认属性属性为应用程序模型的 BOModel 的 Caption 属性指定"Task"值 |演示任务节点。通常,您可以指定应用程序模型的 BOModel 的任何属性 |<Class>或 BOModel |<Class>*自己的会员 |<Member>节点,通过将 ModelDefault 属性应用于业务类或其成员。

  • Modify the Contact class implementation: add the Tasks property as the second part of the Contact-DemoTask relationship. Note that the Association attribute must be applied to this property as well. The following code demonstrates a code snippet from the Contact class implementation.

  • 修改联系人类实现:将 Tasks 属性添加为联系人-演示任务关系的第二部分。请注意,关联属性也必须应用于此属性。以下代码演示了联系人类实现的代码段。

     
    [DefaultClassOptions]
    public class Contact : Person {
    //...
    [Association("Contact-DemoTask")]
    public XPCollection<DemoTask> Tasks {
    get {
    return GetCollection<DemoTask>(nameof(Tasks));
    }
    }
    }

    The code above will automatically generate the required intermediate tables and relationships.

上述代码将自动生成所需的中间表和关系。

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 the Contact Detail View or Task Detail View. Add tasks to a Contact object's Tasks collection, or contacts to a Task object's Contacts collection. To apply the assignment, use the Link button that accompanies these collections.

  • 在实现业务类时,可以使用代码模板。使用代码模板可缩短代码创建时间,因为它有助于避免手动键入整个代码,并允许您只需几个击键即可创建常规代码部分。要了解 eXpress 持久对象的内置代码模板,请参阅 XPO 和 XAF 模板主题。

  • 运行 WinForms 或ASP.NET应用程序。调用联系人详细信息视图或任务详细信息视图。将任务添加到"联系人"对象的"任务"集合,或将联系人添加到"任务"对象的"联系人"集合中。要应用分配,请使用这些集合附带的链接按钮。

You can see the code demonstrated in this lesson in the Contact.cs (Contact.vb) and DemoTask.cs (DemoTask.vb) files 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/

您可以在本课中演示的代码,请参阅与 XAF 一起安装的主演示的Contact.cs (Contact.vb) 和DemoTask.cs (DemoTask.vb) 文件中。默认情况下,主演示应用程序安装在 %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/ 中。ASP.NET版本可在 http://demos.devexpress.com/XAF/MainDemo/ 在线获取

.

.

XAF中多对多关系 (XPO)的更多相关文章

  1. 如何决解项目中hibernate中多对多关系中对象转换json死循环

    先写一下原因吧!我是写的SSH项目,在项目中我遇到的问题是把分页对象(也就是pageBean对象)转化为json数据,下面为代码: public class PageBean <T>{// ...

  2. 关于hibernate中多对多关系

    关于多对多关系 数据库:在使用多对多的关系时,我们能够使用复合主键.也能够不使用,直接引入外键相同能够实现. 在数据库中使用多对多关系时,须要一个中间表. 多对多关系中的数据库结构例如以下: 表:Or ...

  3. Django中多对多关系的orm表设计

    作者的管理 1.设计表结构 出版社 书籍 作者 一个出版社出版多个书籍  1对多 书籍和作者的关系:一个作者写多本书,一本书可以是多个作者写.多对多 1)创建一张表,表中多对多的数据关系.使用 多对多 ...

  4. hibernate 中多对多关系对象集合的保存

    多对多关系映射和一对多关系映射开发步骤差不多, 例子如下:员工和项目之间的关系,一个员工可以参与多个项目:一个项目可以有多个开发人员参与.因此是多对多的关系. 1 分析数据表 1.1)员工表 CREA ...

  5. 数据库中多对多关系的处理 User---Role

    --一个用户可以担任多个角色,如user1既是调度员又是分拣员--一个角色可以被多个用户担任,如user1是调度员,user2也是调度员--用户和角色之间的对应关系为多对多,所以会产生中间表 t_us ...

  6. MyBatis中多对多关系的映射和查询

    先说一下需求: 在页面上显示数据库中的所有图书,显示图书的同时,显示出该图书所属的类别(这里一本书可能同时属于多个类别) 创建表: 笔者这里使用 中间表 连接 图书表 和 图书类别表,图书表中 没有使 ...

  7. SSAS中CUBE的多对多关系既可以出现在中间事实表上也可以出现在中间维度表上

    开发过SSAS中CUBE的朋友,肯定都知道维度用法中的多对多关系, 这篇文章不想详细阐述多对多关系在CUBE中的结构,详情请在网上寻找CUBE多对多关系的介绍资料. 下面是是一个典型的CUBE中多对多 ...

  8. EF(Entity Framework)多对多关系下用LINQ实现"NOT IN"查询

    这是今天在实际开发中遇到的一个问题,需求是查询未分类的博文列表(未加入任何分类的博文),之前是通过存储过程实现的,今天用EF实现了,在这篇博文中记录一下. 博文的实体类BlogPost是这样定义的: ...

  9. Entity Framework 6 Recipes 2nd Edition(10-9)译 -> 在多对多关系中为插入和删除使用存储过程

    10-9. 在多对多关系中为插入和删除使用存储过程 问题 想要在一个无载荷的多对多关系中使用存储过程(存储过程只影响关系的连接表) 解决方案 假设有一个多对多关系的作者( Author)表和书籍( B ...

随机推荐

  1. HTML51-清除浮动overflow、网易注册界面基本结构搭建

    一.overflow:hidden;作用 (1)可以将超出标签范围的内容裁剪掉 (2)清除浮动 .box1{ background-color: red; /*border:1px white sol ...

  2. NLP入门(九)词义消岐(WSD)的简介与实现

    词义消岐简介   词义消岐,英文名称为Word Sense Disambiguation,英语缩写为WSD,是自然语言处理(NLP)中一个非常有趣的基本任务.   那么,什么是词义消岐呢?通常,在我们 ...

  3. Git - Git简介与客户端安装

    简介 Git是目前世界上最先进的分布式版本控制系统(没有之一)! 集中式版本控制系统(CVS/SVN),版本库是集中存放在中央服务器的,而一般工作的时候,用的都是自己的电脑,所以要先从中央服务器取得最 ...

  4. PHP+Mysql统计文件下载次数实例

    PHP+Mysql统计文件下载次数实例,实现的原理也很简单,是通过前台点击链接download.php传参id,来更新点击次数. 获取文件列表: <?php require 'conn.php' ...

  5. Business Model Design 业务模型设计

    Note This section is split into two parts, which describe the use of two different Object-relational ...

  6. 看完这篇文章,我奶奶都知道什么是JVM中的内存模型与垃圾回收!

    扩展阅读:JVM从入门开始深入每一个底层细节 六.内存模型 6.1.内存模型与运行时数据区 Java虚拟机在执行Java程序的过程中会把它所管理的内存划分为若干不同数据区域. Java内存模型的主要目 ...

  7. 代码提示—ArcGIS API forJavaScript for JavaScript 编辑器代码提示(支持3.x和4.x)

    我一般用WebStorm来arcgis api for js的代码,因为api中的内容太多,每次写代码都要去官方API网站查询,很不方便,所以决定配置一个代码补全,方便写接口. 通过ArcGIS AP ...

  8. WebGIS小理论(持续更新)

    什么是OWC服务体系 它是开放地理空间协会(Open Geospatial Consortium,OGC)提出的OGC Web服务通用规范. 主要内容: 地理数据服务(Data Service) 对空 ...

  9. SAP depreciation key config

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

  10. dedecmsV5.7 调用其他站点的数据库的数据的方法

    问题:网站是用dedecmsv5.7写的,后来加了一套论坛discuzX3.4.因为dede要调用dz的数据,本来用jsonp跨域请求的数据,但是m端掉用的时候会把请求的链接的域名后面自动加个/m(不 ...