Skip to Content
0
Jul 27, 2020 at 01:01 PM

odata create entity action in SAP MDK

154 Views

Hi, Posted below is my metadata for 2 entities:

<EntityType Name="CompanyProfile">
                <Key>
                    <PropertyRef Name="Id"></PropertyRef>
                </Key>
                <Property Name="Address" Type="Edm.Int64" Nullable="true"></Property>
                <Property Name="ContactNumber" Type="Edm.String" Nullable="true" MaxLength="255"></Property>
                <Property Name="Id" Type="Edm.Int64" Nullable="false"></Property>
                <Property Name="Version" Type="Edm.Int64"></Property>
                <Property Name="Name" Type="Edm.String"></Property>
                <NavigationProperty Name="LocationDetails" Relationship="default.CompanyProfile_Location_Many_ZeroToOne0" FromRole="CompanyProfile" ToRole="Location"></NavigationProperty>
</EntityType>
<EntityType Name="Location">
                <Key>
                    <PropertyRef Name="Id"></PropertyRef>
                </Key>
                <Property Name="City" Type="Edm.String" Nullable="true"></Property>
                <Property Name="Id" Type="Edm.Int64" Nullable="false"></Property>
                <Property Name="Province" Type="Edm.String" Nullable="true"></Property>
                <Property Name="Region" Type="Edm.Region" Nullable="true"></Property>
                <Property Name="Version" Type="Edm.Int64" Nullable="true"></Property>
</EntityType> 

It has been simplified a bit from the original, but the problem remains the same anyway. As you can see, the CompanyProfile entity has a relation to the Location entity. Also the Address property in CompanyProfile is in fact also the id for the related Location entity. Given this, I try to create a new CompanyProfile related with an existing Location using:

{
    "Version": "1",
    "ContactNumber": "1245",
    "Name": "OIL Tycoon corporation",
    "Status": "OK",
    "Address":  "2"
}

However, that doesn't work. What works is

{    
    "Version": "1",
    "ContactNumber": "1245",
    "Name": "OIL Tycoon corporation",
    "Status": "OK",
    "LocationDetails" : {
    "__metadata": {
                "id": "http://localhost:8080/odata/Locations(2L)",
                "uri": "http://localhost:8080/odata/Locations(2L)",
                "type": "default.Location"
            }
  }
} 

Now the reason I ask for this is because the request being generated by SAP MDK odata action has the data structure of the first, so I get an error with it. The second structure is what I need, but then I have no idea if my odata api is the one thats wrong and the first structure is still correct and should be accepted by my apis(It was created using spring-boot and olingo). Here is the code of the odata action in case it is useful

"CreateLinks": [
{
"Property": "LocationDetails",
"Target": {
"EntitySet": "Locations",
"QueryOptions": "$filter=Id eq 2"
},
"_Enabled": true
}
],
"Properties": {
               "ContactNumber": "1245",
               "Name": "OIL Tycoon corporation",
               "Status": "OK"
       "Version": "1"
},
"Target": {
"EntitySet": "CompanyProfiles",
"Service": "/DOEDocumentMonitoring/Services/DOEDocumentMonitoring.service"
},
"_Type": "Action.Type.ODataService.CreateEntity"
}

Sorry the question is a bit long. I hope I was clear with my explanation of the problem.