on 07-27-2020 2:01 PM
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.
Kindly specify Id also in the Create payload, since it is a mandatory field(nullable = false) :
{"Version": "1","ContactNumber": "1245","Id" : "2", "Name": "OIL Tycoon corporation","Status": "OK","Address": "2"}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rishabh,
The Id in this case is created automatically. I'd like to clarify that basically this is bare minimum for this api, except that Address is not being recognized in the first example that I gave. The api recognizes the second example (Address is also LocationDetails, only in link form or something. I'm sorry I don't really know the specifics of what its called)
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.