首页 > 其他分享 >学习011-03-03 Relationships Between Persistent Objects in Code and UI(代码和用户界面中持久对象之间的关系)

学习011-03-03 Relationships Between Persistent Objects in Code and UI(代码和用户界面中持久对象之间的关系)

时间:2024-09-27 11:50:40浏览次数:3  
标签:Relationships 03 Code nameof 对象 Many Contact return public

Relationships Between Persistent Objects in Code and UI(代码和用户界面中持久对象之间的关系)

When designing a business model, it can be necessary to set specific relationships between business objects. This topic describes how to set these relationships between persistent objects in an XPO application and demonstrates how these relationships will be organized in a UI.
在设计业务模型时,可能需要设置业务对象之间的特定关系。本主题描述如何在XPO应用程序中设置持久对象之间的这些关系,并演示如何在UI中组织这些关系。

Tip
To learn about the relationships between entities in EF Core, refer to the following help topic: Relationships Between Entities in Code and UI (EF Core)
要了解EF Core中实体之间的关系,请参阅以下帮助主题:代码和UI中实体之间的关系(EF Core)

The “Many” side of an association, which is a collection property and displayed in UI using the ListPropertyEditor in WinForms and ASP.NET Web Forms applications. To show the “One” side that is a reference property, LookupPropertyEditor and ASPxLookupPropertyEditor are used in the WinForms and ASP.NET Web Forms applications accordingly. If ExpandObjectMembersAttribute is applied to the reference property with the ExpandObjectMembers.Never parameter, ObjectPropertyEditor is used instead. Each object collection has an individual Actions set, which depends on the collection type. You can manage the New, Delete, Link, or Unlink Action’s visibility in the Model Editor. Set the List View’s AllowNew, AllowDelete, AllowLink, or AllowUnlink property to false to hide these Actions.
关联的“Many”面,这是一个集合属性,并使用WinForms和ASP.NET Web Forms应用程序中的ListProperty tyEditor在UI中显示。要显示作为引用属性的“ One”面,在WinForms中使用LookupPropertyEditor和ASPxLookupPropertyEditor,并相应地ASP.NET Web Forms应用程序。如果ExpandObjectMembersAttribute使用expandObjectMembers.永不参数应用于引用属性,则使用ObjectPropertyEditor。每个对象集合都有一个单独的操作集,这取决于集合类型。您可以在模型编辑器中管理新建、删除、链接或取消链接操作的可见性。将列表视图的AllowNew、AllowDelete、AllowLink或AllowUnlink属性设置为false以隐藏这些操作。

If a child object is aggregated (i.e., this object is considered a part of a master object and decorated with the AggregatedAttribute), an XPNestedObjectSpace Object Space is created for its Detail View, because this object should not be physically saved to the database until its owner is saved. If a child object is not aggregated (i.e., it can exist separately), a separate XPObjectSpace is used for its Detail View. A nested List View where objects from the detail collections are shown uses the same master XPObjectSpace regardless of the aggregation.
如果子对象被聚合(即,该对象被认为是主对象的一部分,并用AggregatedAtoral进行装饰),则为其详细视图创建XPNestedObjectSpace对象空间,因为在保存其所有者之前,不应将该对象物理保存到数据库中。如果子对象没有被聚合(即,它可以单独存在),则为其详细视图使用单独的XPObjectSpace。显示详细集合中的对象的嵌套列表视图使用相同的主XPObjectSpace,而不管聚合如何。

This topic includes the following sections.
本主题包括以下部分。

  • One-to-Many (Non Aggregated)(一对多(非聚合))
  • One-to-Many (Aggregated)(一对多(聚合))
  • Many-to-Many(多对多)
  • One-to-One(一对一)

One-to-Many (Non Aggregated)(一对多(非聚合))

The relationship between the Department and Contacts illustrates the One-to-Many type, when many Contacts can be included into one Department. In this example, Department object contains a child ContactsCollection collection and is the “One” side of its One-to-Many relationship.
部门和联系人之间的关系说明了一对多类型,当许多联系人可以包含到一个部门中时。在此示例中,部门对象包含一个子ContactsCollection集合,并且是其一对多关系的“ One”面。

在这里插入图片描述
在这里插入图片描述

The List View that displays the ContactsCollection is accompanied by a New Action. This Action allows end-users to add new Contact objects to one of the existing Department objects (including the current object). In addition, the Link and Unlink Actions are available and allow you to add and remove a reference to a Contact object from another collection.
显示ContactsCollection的列表视图伴随着一个新操作。此操作允许最终用户将新的联系人对象添加到现有的部门对象之一(包括当前对象)。此外,链接和取消链接操作可用,并允许您从另一个集合中添加和删除对联系人对象的引用。

Nonaggregated objects are created in their own Object Space. So, the new Contact objects created within the Department Detail View can be saved separately from the parent object.
非聚合对象在它们自己的对象空间中创建。因此,在部门详细信息视图中创建的新联系人对象可以与父对象分开保存。

The following code demonstrates how you can implement this type of relationship.
以下代码演示了如何实现这种类型的关系。

C#
[DefaultClassOptions]
public class Contact : XPObject {
    //...
    private Department department;
    [Association("Department-Contacts")]
    public Department Department {
        get { return department; }
        set { SetPropertyValue(nameof(Department), ref department, value); }
    }
}
[DefaultClassOptions]
public class Department : XPObject {
    //...
    [Association("Department-Contacts")]
    public XPCollection<Contact> ContactsCollection {
        get { return GetCollection<Contact>(nameof(ContactsCollection)); }
    }
}

One-to-Many (Aggregated)(一对多(聚合))

Let’s assume that a Contact has a collection of Notes, which are aggregated with their parent Contact. In this case, the Note object declares the “One” aggregated side of the One-to-Many relationship with the Contact object.
让我们假设一个联系人有一个Notes集合,它们与它们的父联系人聚合。在这种情况下,Note对象声明了与联系人对象的一对多关系的“One”聚合端。
在这里插入图片描述

在这里插入图片描述

The List View that displays the NotesCollection is accompanied by the New Action. This Action allows end-users to add new Note objects. Note that in this instance, the Contact property of the new Note objects will be automatically set to the current Contact and this editor is not displayed in the UI.
显示NotesCollection的列表视图伴随着新操作。此操作允许最终用户添加新的Note对象。请注意,在这种情况下,新Note对象的联系人属性将自动设置为当前联系人,并且此编辑器不会显示在UI中。

Aggregated objects are created in the parent object’s Object Space. So, the new Note objects created within the Contact Detail View will be saved when their parent object is saved, and will be deleted when their parent object is deleted (cascade deletion mechanism).
聚合对象是在父对象的对象空间中创建的。因此,在联系人详细信息视图中创建的新Note对象将在保存其父对象时保存,并在删除其父对象时删除(级联删除机制)。

The following code demonstrates how you can implement this type of relationship.
以下代码演示了如何实现这种类型的关系。

C#
[DefaultClassOptions]
public class Contact : XPObject {
    //...
    [Association("Contact-Notes"), DevExpress.Xpo.Aggregated]
    public XPCollection<Note> NotesCollection {
        get { return GetCollection<Note>(nameof(NotesCollection)); }
    }
}
[DefaultClassOptions]
public class Note : XPObject {
    //...
    private Contact contact;
    [Association("Contact-Notes")]
    public Contact Contact {
        get { return contact; }
        set { SetPropertyValue(nameof(Contact), ref contact, value); }
    }
}

Many-to-Many(多对多)

For example, each Contact can have a collection of Tasks and each Task can be assigned to a number of Contacts. Thus, the relationship between the Contact and Task objects is named Many-to-Many.
例如,每个联系人可以有一个任务集合,每个任务可以分配给多个联系人。因此,联系人和任务对象之间的关系被命名为多对多。
在这里插入图片描述

在这里插入图片描述

The List View that displays the TasksCollection is accompanied by the Link Action. This Action allows end-users to add references to existing Task objects. If the NewObjectViewController.LinkNewObjectToParentImmediately property is set to true, the New Action is not applied to this collection. This behavior complies with the unique concept of the Many-to-Many relationship. However, you can create a new Task in the Link Action’s pop-up window.
显示TasksCollection的列表视图伴随着链接操作。此操作允许最终用户添加对现有任务对象的引用。如果NewObjectViewController.LinkNewObjectToParentImmediately属性设置为true,则新操作不会应用于此集合。此行为符合多对多关系的独特概念。但是,您可以在链接操作的弹出窗口中创建一个新任务。

The Unlink Action is also provided for the TasksCollection. This Action allows end-users to remove references to Task objects from the collection.
还为TasksCollection提供了Unlink Action。此操作允许最终用户从集合中删除对Task对象的引用。

The following code demonstrates how you can implement this type of relationship.
以下代码演示了如何实现这种类型的关系。

Technique 1**(技巧1)**

C#
[DefaultClassOptions]
public class Contact : XPObject {
    //...
    [Association("Contacts-Tasks")]
    public XPCollection<Task> TasksCollection {
        get { return GetCollection<Task>(nameof(TasksCollection)); }
    }
}
[DefaultClassOptions]
public class Task : XPObject {
    //...
    [Association("Contacts-Tasks")]
    public XPCollection<Contact> ContactsCollection {
        get { return GetCollection<Contact>(nameof(ContactsCollection)); }
    }
}

Technique 2 (with an Intermediate Object)(技术2(带有中间对象))

C#
using DevExpress.ExpressApp.Security;
using DevExpress.Persistent.Base;
using DevExpress.Xpo;
using System.Collections.Generic;
using System.ComponentModel;
// ...
[DefaultClassOptions]
public class Contact : XPObject {
    // ...
    [Browsable(false)]
    [Association("Contact-ContactTasks"), Aggregated]
    public XPCollection<ContactTask> ContactTasks {
        get { return GetCollection<ContactTask>(nameof(ContactTasks)); } }
    [ManyToManyAlias(nameof(ContactTasks), nameof(ContactTask.Task))]
    public IList<Task> TaskCollection {
        get { return GetList<Task>(nameof(TaskCollection)); }
    }
}
[DefaultClassOptions]
public class Task : XPObject {
    // ...
    [Browsable(false)]
    [Association("Task-ContactTasks"), Aggregated]
    public XPCollection<ContactTask> ContactTasks {
        get { return GetCollection<ContactTask>(nameof(ContactTasks)); } }
    [ManyToManyAlias(nameof(ContactTasks), nameof(ContactTask.Contact))]
    public IList<Contact> ContactCollection {
        get { return GetList<Contact>(nameof(ContactCollection)); }
    }
}
// Uncomment the following line if your application uses the Security System.
// [IntermediateObject(nameof(Contact), nameof(Task))]
public class ContactTask : XPObject {
    public ContactTask(Session session) : base(session) { }
    Contact fContact;
    [Association("Contact-ContactTasks")]
    public Contact Contact {
        get { return fContact; }
        set { SetPropertyValue<Contact>(nameof(Contact), ref fContact, value); }
    }
    Task fTask;
    [Association("Task-ContactTasks")]
    public Task Task {
        get { return fTask; }
        set { SetPropertyValue<Task>(nameof(Task), ref fTask, value); }
    }
}

For more information on this technique, refer to the following help topic: Relationships Between Objects.
有关此技术的更多信息,请参阅以下帮助主题:对象之间的关系。

One-to-One(一对一)

If each Contact can have only one unique Address and one Address can’t be assign to many Contacts, this relationship is the One-to-One.
如果每个联系人只能有一个唯一的地址,并且一个地址不能分配给多个联系人,则这种关系是一对一的。
在这里插入图片描述

在这里插入图片描述

This relationship doesn’t provide a collection side. Note that in this instance, the Contact property of the new Address objects will be automatically set to the current Contact.
此关系不提供集合端。请注意,在这种情况下,新Address对象的联系人属性将自动设置为当前联系人。

The following code demonstrates how you can implement this type of relationship.
以下代码演示了如何实现这种类型的关系。

C#
[DefaultClassOptions]
public class Contact : XPObject {
    //...
    [Aggregated]
    private Address address;
    public Address Address{
        get { return address; }
        set {
            if (address == value) return;
            Address prevAddress = address;
            address = value;
            if (IsLoading) return;
            if (prevAddress!= null && prevAddress.Contact == this)
                prevAddress.Contact = null;
            if (address != null)
                address.Contact = this;
            OnChanged(nameof(Address));
        }
    }
}
[DefaultClassOptions]
public class Address : XPObject {
    //...
    Contact contact = null;
    public Contact Contact {
        get { return contact; }
        set {
            if (contact == value)
                return;
            Contact prevContact = contact;
            contact = value;
            if (IsLoading) return;
            if (prevContact != null && prevContact.Address == this)
                prevContact.Address = null;
            if (contact != null)
                contact.Address = this;
            OnChanged(nameof(Contact));
        }
    }
}

标签:Relationships,03,Code,nameof,对象,Many,Contact,return,public
From: https://blog.csdn.net/thomastang200912_126/article/details/142590157

相关文章

  • python+vue中小学班级课外活动管理系统pycharm毕业设计项目_0390d
    目录解决的思路技术栈和环境说明python语言操作可行性性能/安全/负载方面具体实现截图框架介绍技术路线python-flask核心代码部分展示python-django核心代码部分展示详细视频演示源码获取解决的思路前端的数据收集及可视化研究,熟悉Django框架,python编程设计语法。......
  • 03安装及管理程序
    软件包分类:一.源码包.tar.gz.tar.bz2优点:1.开源2.需要通过编译进行安装,但是与系统比较契合缺点:1.步骤较多2.编译时间较长3.编译安装时会报错,不适合新手。二、RPM(RedHatPackageManager)安装包:用于管理Linux各项套件的程序。优点:1.包管理简单,通过几个......
  • 【LeetCode Hot 100】21. 合并两个有序链表
    题目描述最简单粗暴的想法是将两个链表的所有元素拿出来放在一个数组中,再将此数组排序,最后生成一个新链表并返回。由于给出的参数本身就是两个排好序的链表,可以进行一次遍历,就能保证元素仍然是有序的:每次比较当前指针指向的两个元素的大小,较小的拿出来作为当前元素并将指针向前移......
  • 易优CMS网站SQLSTATE[42S22]: Column not found: 1054 Unknown column 'a. province_i
    当你遇到“SQLSTATE[42S22]:Columnnotfound:1054Unknowncolumn'a.province_id'in'whereclause'”的错误提示时,通常是因为查询中引用了一个不存在的列。以下是一些具体的解决步骤:步骤1:检查数据库表结构确认表结构确认数据库表中是否存在 province_id 列。使用......
  • 03 json支持的类型: 爬虫场景使用的比较多。
    #json支持的类型:爬虫场景使用的比较多。+-------------------+---------------+|Python|JSON|+===================+===============+|dict|object|+-------------------+---------------+|l......
  • LeetCode刷题日记之二叉树(二)
    目录前言左叶子之和找树左小角的值总结前言经过数模比赛的四天忙碌后博主继续开始LeetCode学习了,给大家分享学习心路的同时也是在不断勉励自己每天把自己的学的东西去进行一个产出记录,不足的地方欢迎大家批评指正,一起加油吧朋友们!......
  • 03 sys.argv 运维使用比较多
    sys.argv运维使用比较多获取用户执行脚本时,传入的参数,将执行空格后的路径,进行append到一个列表让用户执行脚本传入要删除的文件路径,在内部帮助用完后将目录删除#!/usr/bin/envpython#-*-coding:utf-8-*-"""让用户执行脚本传入要删除的文件路径,在内部帮助用将目录删除......
  • 在 VS Code 中配置 C/C++ 开发环境(详细指南)
    前言VisualStudioCode(VSCode)是一个广泛使用的代码编辑器,支持多种编程语言,包括C和C++。本指南将详细介绍如何在VSCode中设置C/C++开发环境,适合新手。1.安装编译器1.1.Windows系统推荐使用MinGW-w64:下载MinGW-w64访问MinGW-w64官网。选择适合你系统......
  • 解决 Nodejs 中的“Punycode Module is Deprecated”问题
    大家好,我叫asimkhan,目前是metamelon的全栈开发人员。最近,我在为naseebi.com(一个婚姻移动和web应用程序)项目工作时遇到了一个令人沮丧的问题。该问题涉及node.js中punycode模块的弃用,我想与您分享我的经验和解决方案。问题在应用程序中使用配置文件创建功能时,我......
  • 流行的 Visual Studio Code 扩展
    流行的VisualStudioCode扩展2024Prettier:代码格式化程序:自动格式化代码以确保风格一致。实时服务器:启动具有静态和动态内容实时重新加载功能的本地开发服务器。Docker:可以轻松管理Docker容器和镜像、构建和部署Docker应用程序。括号对着色器2:匹配括号的颜色以提高复杂......