8

Importing an external data model using CDS Graphical Modeler for Visual Studio C...

 1 year ago
source link: https://blogs.sap.com/2022/05/09/importing-an-external-data-model-using-cds-graphical-modeler-for-vscode/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
May 9, 2022 4 minute read

Importing an external data model using CDS Graphical Modeler for Visual Studio Code

0 4 101

In this blog post, we’ll demonstrate how to import an external OData data model from an edmx file to an existing CDS model, and create a relationship to one of the OData entities from this external data model through the CDS Graphical Modeler for Visual Studio Code.

Preparing the External Data Model

First install the CDS Graphical Modeler for VSCODE from the VSCODE Marketplace at https://marketplace.visualstudio.com/items?itemName=SAPSE.vscode-wing-cds-editor-vsc. More details about the CDS Graphical Modeler for Visual Studio Code can be found at the previous blog post https://blogs.sap.com/2022/04/29/an-introduction-to-cds-graphical-modeler-for-visual-studio-code/.

After preparing your CDS project at VSCODE, open your cds model through the CDS Graphical Modeler. Then try to create an entity by clicking the “Add Entity” toolbar button:

2022-05-09_14-07-06.png

Create a “Customers” entity on the entity dialog in the model:

2022-05-09_14-11-50.png

Click “Create” button and close the dialog, and you will see that the new “Customers” entity has been created:

2022-05-09_14-13-47.png

Now before importing the external data model, copy the edmx file that contains the OData model to your project:

2022-05-09_14-15-10.png

You can also look into the OData model through the OData CSDL Modeler which is also a VSCODE extension by installing the tool at https://marketplace.visualstudio.com/items?itemName=SAPSE.vsc-extension-odata-csdl-modeler. More details about the OData CSDL Modeler can be found at the previous blog post https://blogs.sap.com/2022/05/05/an-introduction-to-odata-csdl-modeler-for-visual-studio-code/.

Open the edmx file using the CSDL modeler:

2022-05-09_14-18-20.png

Since the imported edmx file contains a complex OData model, you can locate the external model by clicking the “Search” button from the toolbar that launches the entity search dialog:

2022-05-09_14-19-10.png

Suppose you’re importing the “BusinessPartner” entity into your CDS model, now type “businesspartner” to locate your entity:

2022-05-09_14-21-33.png

Click the entity type in the list:

2022-05-09_14-23-11.png

The entity will be shown in the canvas. You can then check the details of this entity from both the canvas as well as the property sheet:

2022-05-09_14-24-23.png

Importing an External Data Model using CDS Graphical Modeler

Let’s go back to the CDS model. Click “Import” button on the model:

2022-05-09_14-25-49.png

Click “External Files” menu item:

2022-05-09_14-27-32.png

Select the edmx file and click “Open” button to close the dialog:

2022-05-09_14-28-25.png

You can optionally provide an alias for the imported data model, otherwise click “OK” button to finish the import. CDS model will navigate to the imported namespace automatically:

2022-05-09_14-30-15.png

Click the “Home” button to go back to your main CDS namespace:

2022-05-09_14-31-28.png

If we try to create an association from the newly created “Customers” entity to the business partner entity, select the entity and click “Add Relationship” context menu:

2022-05-09_14-32-19.png

You will see the linkage line moving along with your mouse. Since the target entity is not in the current namespace we can point the line directly to the target entity as described in the blog post https://blogs.sap.com/2022/05/03/creating-entity-relationship-through-cds-graphical-modeler-for-vscode/. Click your mouse at any empty canvas space:

2022-05-09_14-34-36.png

This will launch the relationship dialog:

2022-05-09_14-36-42.png

In the “Target Entity Type” drop down list, type in “businesspartner” to filter the entity types:

2022-05-09_14-37-20.png

Select the business partner entity from the drop down list:

2022-05-09_14-38-27.png

Click “Create” button and close the dialog:

2022-05-09_14-39-30.png

Now we have successfully created a managed association from our data model to an external entity that is from an imported OData model in an edmx file.

Conclusion

In the blog post, we demonstrate how to import an external OData model from an edmx file to the CDS model, and how to create an association from an CDS entity to an external entity. We have also shown how to check the OData model using the OData CSDL Modeler and locate the entity we want to import.

References

An introduction to CDS Graphical Modeler for Visual Studio Code

Creating entity relationship through CDS Graphical Modeler for VSCODE

An introduction to OData CSDL Modeler for Visual Studio Code


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK