What is the role of entity type key in OData metadata definition

Time:2021-12-28

What is the key of OData entity type?

The most authoritative definition comes from ODataOfficial website

What is the role of entity type key in OData metadata definition

The core concepts of OData EDM model are entity entities and associations Entities are instances of entity types (e.g., customers, employees, etc.) described by the OData model. They are structured records, composed of name and strongly typed attributes, with a key

Complex types are structured types, which are also composed of attribute lists, but do not have keys. Therefore, they can only exist as attributes containing entities or as temporary values, but cannot exist alone.

OData complex types are very similar to the structure in ABAP DDIC.

The entity key consists of one or more OData entities attributes (for example, CustomerID or OrderID), which are used toonlyThe basic concept of identifying entity type instances and allowing entity type instances to participate in relationships.

It is illustrated by specific examples.

The following is the Northwind OData metadata URL:

https://services.odata.org/v2…$metadata

What is the role of entity type key in OData metadata definition

From the result list, we can see that there is an EntityType with the name of category and the key of categoryid

To view all categories in the system, first find the entityset corresponding to the entity type category:

What is the role of entity type key in OData metadata definition

Search according to the keyword entityset in the metadata, and then you can find the entityset corresponding to category, whose name is categories

Then splice the categories to the end of the URL to get all the categories of the system:

https://services.odata.org/v2…$format=json

Total 8 pieces of data:

What is the role of entity type key in OData metadata definition

What is the role of entity type key in OData metadata definition

We can pass in the categoryid and find the corresponding category data according to this key:

https://services.odata.org/v2…(3)?$format=json

What is the role of entity type key in OData metadata definition

Syntax for accessing a single entity according to key: entityset name + (key value)

What is the role of entity type key in OData metadata definition

Except for key, OData does not support querying through the syntax of putting other attributes of entity in parentheses.

An attempt was made to find a category instance with a CategoryName of contracts, syntax error:

What is the role of entity type key in OData metadata definition

For the query based on the non key attribute, use the OData $filter operation:

https://services.odata.org/v2…$filter=CategoryName eq ‘Confections’

What is the role of entity type key in OData metadata definition

More Jerry’s original articles are: “Wang Zixi”:
What is the role of entity type key in OData metadata definition