Skip to Content
Technical Articles

Showing and hiding auto-exposed CDS entities in a CDS service

In CDS, some entities are automatically exposed in a CDS service, for example, entities of compositions for an entity that has been exposed as a projection in a CDS service. In the CDS Graphical Modeler, we have a user option to control how to show and hide those auto-exposed entities in a CDS service.

Let’s assume you have below CDS entity model:

namespace my.bookshop;

using
{
    cuid,
    managed,
    temporal
}
from '@sap/cds/common';

entity Books : cuid, managed, temporal
{
    title : String;
    stock : Integer;
    chapters : Composition of many Chapters on chapters.book = $self;
    pages : Composition of many Pages on pages.book = $self;
    author : Association to one Authors;
    backgrounds : Composition of many Backgrounds on backgrounds.book = $self;
    bookInfo : Composition of one BookInfos on bookInfo.book = $self;
    covers : Composition of many Covers on covers.book = $self;
}

entity Chapters : cuid, managed, temporal
{
    book : Association to one Books;
}

entity Pages : cuid, managed, temporal
{
    book : Association to one Books;
}

entity Authors : cuid, managed, temporal
{
}

entity Covers : cuid, managed
{
    book : Association to one Books;
}

entity Backgrounds : cuid, managed
{
    book : Association to one Books;
}

entity BookInfos : cuid, managed, temporal
{
    book : Association to one Books;
}

And if you take a look at the Books entity, it has 5 compositions that point to Chapters, Pages, Backgrounds, BookInfos and Covers. Let’s open the CDS model using the CDS Graphical Modeler:

Now let’s create a projection for entity Books in a CDS service:

And you will see below created projection for entity Books:

We can now open the user preferences of SAP Business Application Studio:

In the CDS Graphical Modeler section, check “Show Auto-Exposed Entities”:

Go back to the CDS Graphical Modeler for the CDS service, close the CDS file and reopen it and this time you see the auto-exposed entities in the CDS service:

As a summary, in this blog post we demonstrate how to hide and how the entities that are automatically exposed in the CDS service through a user preference option for the CDS Graphical Modeler in the SAP Business Application Studio, so that the user would understand the CDS service model better even at design time before actually deploying the model and check the OData meta data at runtime.

Be the first to leave a comment
You must be Logged on to comment or reply to a post.