What is the key of OData entity type?
The most authoritative definition comes from ODataOfficial website：
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:
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:
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:
Total 8 pieces of data:
We can pass in the categoryid and find the corresponding category data according to this key:
Syntax for accessing a single entity according to key: entityset name + (key value)
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:
For the query based on the non key attribute, use the OData $filter operation:
https://services.odata.org/v2…$filter=CategoryName eq ‘Confections’
More Jerry’s original articles are: “Wang Zixi”: