Association and Navigation
Let’s keep things simple to understand. To under stand Association and Navigation in oData, let’s work on simple FLIGHT Model data.
Let’s display all the entries from the SCARR table and Now user wants to see all dependent records from SPFLI table based on Carrier ID(CARRID) which can be achieved through association and navigation.
Let’s build a oDATA project in Tx- SEGW.
We have to design entity types and entity sets for both SCARR and SPFLI structure.
One Entity Type and Entity Set is created.
Create one more entity type and entity set for SPLFI structure.
Choose few/all fields.
Define the key fields.
We are ready with 2 entity types and entity sets. Now we can set up a association between two.
Let’s create an association.
Provide a association name and the entity types.
Principal Entity- Scarr and the target/dependent entity- Spfli.
Provide the cardinality: 1 to Many
And also provide the Navigation Property Name.
The below screen appears, now we have to maintain the match up fields.
For dependent entity, from F4 provide dependent property as Carrid.
Create association set, than links the entity sets. Choose Finish.
All we can see below, the created association, association sets, referential constraints.
Time to generate the run time artifacts.
Yes to continue.
All generated successfully.
Now we have to implement the GET_ENTITY & GET_ENTITYSET method for both entity types.
SCARR- GET_ENTITY method
SCARR- GET_ENTITYSET method
SPFLI- GET_ENTITY method
SPFLI- GET_ENTITYSET method
Now we have to register the SERVICE.
Choose Add Service.
Search and add.
Call browser to test.
In addition to the basics, it shows the navigation and association properties.
Let’s query entity set: ScarrSet ( in json format).
It shows all records from SCARR table and along with the URL for the NAVIGATION property for each Carrid.
In JSON format view, you can directly click on the navigation view for each Carrid and that will show the dependent records from SPFLI.
For carrid = ‘LH’, we have 4 dependent records.
let’s query for the Scarr Entity – Carrid(‘JL’) in xml format.
Its like below and shows the href link for the Navigation.
Let’s view it in JSON format.