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. vue的provide和inject特性

    由来 组件之间的通信可以通过props和$emit的方式进行通信,但是如果组件之间的关系非常复杂的话,通过以上的方式会很麻烦,并且程序会非常脆弱,没有建中性可言. 在==vue2.2.0 中新增pro ...

  2. Slickflow.NET 开源工作流引擎快速入门之二: 简单并行分支流程代码编写示例

    前言:对于急切想了解引擎功能的开发人员,在下载版本后,就想尝试编写代码,完成一个流程的开发和测试.本文试图从一个最简单的并行分支流程来示例说明,如何快速了解引擎代码的编写. 版本:.NET Core2 ...

  3. error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

    这个报错一般是因为你图像的路径写错了,找不到图像而导致的. 解决问题的朋友麻烦点个推荐呗!嘿嘿

  4. 个人项目开源之Django文件中转站源代码

    可以当做文件中转站或网盘 源代码

  5. 单片机固件烧录器 Firmware Writer Android APP

    GitHub地址 :https://github.com/WallBreakerX/mcu_firmware_writing_via_androidphone ​ 用途 可在安卓手机上实现向单片机的h ...

  6. bay——安装_Oracle 12C-单实例-Centos7.txt

    安装Oracle12C 总结笔记 IP:10.20.4.214 ---------------------------------------------用户和密码: root/bayaimbayai ...

  7. (入门SpringBoot)SpringBoot加接口操作日志好方法(九)

    用Spring的切面去做,慕课网上的大神的小妙招,被我拷贝下来了.import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotati ...

  8. React 修改获取state中的值

    14===> 修改state中的值 不能够直接修改 state = { num: 10 } 如 this.state.num+=12; 不能够直接修改 错误 通过 this.setState({ ...

  9. Codeforces Round #598 (Div. 3)

    传送门 A. Payment Without Change 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/4 21:19:19 */ #i ...

  10. vuex中module的命名空间概念

    vuex中module的命名空间概念 默认情况下,模块内部的 action.mutation 和 getter 是注册在全局命名空间的. 弊端1:不同模块中有相同命名的mutations.action ...