on 12-23-2021 5:53 AM
I have a synonymn and defined in data model with @cds.persistence.exists and I have also defined the association in the data model (only at CAP not in source table) . But when I run the service metadata I don't see the Navigation property.
@cds.persistence.exists
entity Books {
ID : Integer;
author : Association to Authors on author.ID=ID;
}
@cds.persistence.exists
entity Authors {
ID : Integer;
books : Association to Books on Books.ID= ID;
}
I also tried
extend Books with {
author : Association to Authors on author.ID = ID
}
I am not sure if it is possible to add an association to synonyms . Can you please suggest me what I am doing wrong here?
Hi,
you have to wrap your entities into a service like so:
service MyService {
@cds.persistence.exists
entity Books {
key ID : Integer;
author : Association to Authors
on author.ID = ID;
}
@cds.persistence.exists
entity Authors {
key ID : Integer;
books : Association to Books
on books.ID = ID;
}
}
Alternatively, you could also create projections on your entities in a service.
Then you will see the Navigation Property in the metadata:
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
<edmx:DataServices>
<Schema Namespace="MyService" xmlns="http://docs.oasis-open.org/odata/ns/edm">
<EntityContainer Name="EntityContainer">
<EntitySet Name="Books" EntityType="MyService.Books">
<NavigationPropertyBinding Path="author" Target="Authors"/>
</EntitySet>
<EntitySet Name="Authors" EntityType="MyService.Authors">
<NavigationPropertyBinding Path="books" Target="Books"/>
</EntitySet>
</EntityContainer>
<EntityType Name="Books">
<Key>
<PropertyRef Name="ID"/>
</Key>
<Property Name="ID" Type="Edm.Int32" Nullable="false"/>
<NavigationProperty Name="author" Type="MyService.Authors">
<ReferentialConstraint Property="ID" ReferencedProperty="ID"/>
</NavigationProperty>
</EntityType>
<EntityType Name="Authors">
<Key>
<PropertyRef Name="ID"/>
</Key>
<Property Name="ID" Type="Edm.Int32" Nullable="false"/>
<NavigationProperty Name="books" Type="MyService.Books">
<ReferentialConstraint Property="ID" ReferencedProperty="ID"/>
</NavigationProperty>
</EntityType>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
Did this help?:)
Best Regards,
Patrice
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
9 | |
9 | |
8 | |
7 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.