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. mesos-slave启动不起来

    刚开始时候的状态 后来装了docker后

  2. python 对字典分别按照key值、value值进行排序

    1.sorted函数首先介绍sorted函数,sorted(iterable,key,reverse),sorted一共有iterable,key,reverse这三个参数. 其中iterable表示 ...

  3. ES6-Set的增加、查找、删除、遍历、查看长度、数组去重

    set 是es6新出的一种数据结构,里边放的是数组. 作用:去重(set里边的数组不能重复) MDN:Set 对象允许你存储任何类型的唯一值,无论是原始值或者是对象引用. 总结: 1.成员唯一.无序且 ...

  4. [转]VBA Check if an outlook folder exists; if not create it

    本文转自:http://www.outlookcode.com/d/code/quarexe.htm To quarantine application file attachments This O ...

  5. CamlQuery对SharePointOnline List 发起查询请求

    最近的项目中遇到了一个需求,需要向SharePointList 查询Item是否存在,找到了CamlQuery这样一个方法,但是没有找到使用这个接口的频率限制说明文档,于是就有了这篇随笔. 新接触这个 ...

  6. jmeter测试并发

    由于生产出现个并发问题,本地没法重现.后来网上有人说使用jmeter可以测试并发,也有人说postman可以测试.但本着试试新鲜的东西,就用jmeter. 到apache上面下载. 下载加压,然后运行 ...

  7. mago3DJS 应用

    用于3D多块可视化的开源JavaScript库 生成3D GIS平台,集成和可视化AEC(建筑,工程,建筑)区域和传统的3D空间信息(3D GIS).将AEC和3D GIS集成到Web浏览器中,室内, ...

  8. python获取指定文件夹下的文件和文件夹

    import os filepaths = []; dirpaths = []; pathName = r'C:\anfei\json\20191128' for root, dirs, files ...

  9. vue预览本地图片

    <template> <div> <a href="javascript:void(0);" @change="addImage" ...

  10. Node.js接口避免重复启动

    众所周知,一个Node接口要是想被调用,得先在命令行中执行如下代码来启动接口 node base.js 但是一旦修改了base.js,就得重新执行这句命令 注:这里的base.js是我的node接口文 ...