生成实体关系Build a relationship between entities

一个实体中的数据通常与另一个实体中的数据相关。Data in one entity often relates to data in another entity. 例如,你可能有“Customers”和“Orders”实体,而“Orders”实体可能与“Customers”实体有查阅关系,以显示是哪个客户下达订单的。For example, you might have a Customers entity and an Orders entity, and the Orders entity might have a lookup relation to the Customers entity to show which customer placed the order. 可以使用查阅字段显示“Customers”实体中下达订单的用户的相关数据。You can use a lookup field to show data from the Customers entity for the customer who placed the order. 有关详细信息,请参阅实体关系和查阅字段For more information, see Entity relationships and lookup fields.

定义关系Define a relationship

可以创建从一个实体到另一个实体(或实体与其自身之间)的几种类型的关系。You can create several types of relationships from one entity to another (or between an entity and itself). 一个实体可以与多个实体有关系,并且一个实体可以与另一个实体有多种关系。Each entity can have a relationship with more than one entity, and each entity can have more than one relationship to another entity. 一些常见关系类型如下:Some common relationship types are:

  • 正常 - 这种关系存在于两个实体之间。Normal - This type of relationship exists between two entities.
  • 自身 - 这种关系存在于实体与其自身之间。Self - This type of relationship exists between an entity and itself.
  • 一对一 - 在这种关系中,实体 A 中的每条记录只能与实体 B 中的一条记录匹配,反之亦然。One-to-one - In this type of relationship, each record in entity A can match only one record in entity B, and vice versa. 最新版 Common Data Service 不支持具有这种关系的自定义实体。The current release of the Common Data Service does not support this type of relationship for custom entities.
  • 一对多 - 在这种关系中,实体 A 中的每条记录可与实体 B 中的多条记录匹配,但实体 B 中的每条记录只能与实体 A 中的一条记录匹配。One-to-many - In this type of relationship, each record in entity A can match more than one record in entity B, but each record in entity B can match only one record in entity A.
  • 多对多 - 在这种关系中,实体 A 中的每条记录可与实体 B 中的多条记录匹配,反之亦然。Many-to-many - In this type of relationship, each record in entity A can match more than one record in entity B, and vice versa. 最新版 Common Data Service 不支持这种关系。The current release of the Common Data Service doesn't support this type of relationship.

添加查阅关系Add a lookup relation

若要向实体添加查阅关系,请在“关系”选项卡下创建关系,并指定要与之有关系的实体。To add a lookup relation to an entity, create a relation under the Relationships tab and specify the entity with which you want to create a relationship.

  1. powerapps.com 上,展开“Common Data Service”部分,然后单击或点击左侧导航窗格中的“实体”。On powerapps.com, expand the Common Data Service section and click or tap Entities in the left navigation pane.
  2. 在实体列表中,单击或点击某个实体即可显示其字段。In the list of entities, click or tap an entity to display its fields. 在列表上方的搜索栏中键入一个或多个字符可以筛选该列表。You can filter the list by typing one or more characters in the search bar above the list.
  3. 单击或点击屏幕顶部附近的“关系”。Near the top of the screen, click or tap Relationships. 此选项卡显示了实体的所有关系。This tab shows you all of the relationships for the entity. 单击“新建关系”。Click New relationship.
  4. 在“创建关系”页面上,指定要与之有关系的相关实体,然后指定关系的名称和显示名称。On the Create relationship page, specify the related entity with which you want to create a relationship and then, specify the name and display name of the relation.
  5. 单击或点击“保存”以提交更改。Click or tap Save to commit the changes. 此时,系统会自动创建同名的查阅字段。A lookup field with the same name will be automatically created.

在应用中使用查找字段Use a lookup field in an app

如果在包含查阅字段的实体的基础之上自动创建应用,此实体会显示为“下拉列表”控件,折叠时其中包含引用实体的“主键”字段数据。If you create an app automatically from an entity that contains a lookup field, it appears as a Drop down control that contains data from the primary key field of the referred entity in a collapsed state. 若要让展开的下拉列表显示两个字段,必须将“PrimaryId”字段和所选的第二个字段添加到查阅关系的相关实体的“默认查阅”字段组。To see two fields in the drop down when it is expanded, you must add the PrimaryId field and a second field of your choice to the Default Lookup field group of the related entity of the lookup relation.

删除有查阅关系的记录Delete a record with a lookup relation

如果实体 A 与实体 B 有查阅关系:If entity A has a lookup relation to entity B:

  • 可以无限制地删除实体 A 中的任何记录。You can delete any record in entity A without restriction.
  • 如果实体 B 中的一条记录与实体 A 中的一条或多条记录匹配,则必须先删除实体 A 中的所有匹配记录,然后才能删除实体 B 中的记录。If a record in entity B matches one or more records in entity A, you must delete all matching records in entity A before you can delete the record in entity B.

注意:当实体 B 是与实体 A 有父关系的标准实体时,如果从实体 A 中删除一条记录,也会删除实体 B 中的所有匹配记录。Note: If entity B is a standard entity with a parent relationship to entity A and you delete a record from entity A, all matched records in entity B are also deleted.

有关如何删除字段的信息,请参阅 管理字段For information about how to delete a field, see Manage fields.

后续步骤Next steps