Skip to content

Fix wrong links generated for derived type with navigation property when odata.metadata=full - #831

Merged
gathogojr merged 1 commit into
OData:mainfrom
gathogojr:fix/797-wrong-links-for-derived-type-with-navigation-property
Feb 1, 2023
Merged

Fix wrong links generated for derived type with navigation property when odata.metadata=full#831
gathogojr merged 1 commit into
OData:mainfrom
gathogojr:fix/797-wrong-links-for-derived-type-with-navigation-property

Conversation

@gathogojr

Copy link
Copy Markdown
Contributor

This pull request fixes #797.

Description

Fix wrong links generated for derived type with navigation property when odata.metadata=full. When odata.metadata=full is specified, the type-cast segment is wrongly appended to the resource id.

When that happens, since ODL also appends the type-cast segment, you end up with the response payload looking as follows:

{
    "@odata.context": "http://localhost:5219/odata/$metadata#Customers/ODataAlternateKeySample.Models.GoldCustomer/$entity",
    "@odata.type": "#ODataAlternateKeySample.Models.GoldCustomer",
    "@odata.id": "http://localhost:5219/odata/Customers(1)/ODataAlternateKeySample.Models.GoldCustomer",
    "@odata.editLink": "Customers(1)/ODataAlternateKeySample.Models.GoldCustomer/ODataAlternateKeySample.Models.GoldCustomer",
    "Id": 1,
    "Name": "Tom",
    "CountryOrRegion": null,
    "Passport": null,
    "SSN": "SSN-1-101",
    "Titles@odata.type": "#Collection(String)",
    "Titles": [ "abc", null, "efg" ],
    "Contact@odata.associationLink": "http://localhost:5219/odata/Customers(1)/ODataAlternateKeySample.Models.GoldCustomer/ODataAlternateKeySample.Models.GoldCustomer/Contact/$ref",
    "Contact@odata.navigationLink": "http://localhost:5219/odata/Customers(1)/ODataAlternateKeySample.Models.GoldCustomer/ODataAlternateKeySample.Models.GoldCustomer/Contact"
}

This pull request fixes the generation of @odata.id, @odata.editLink, @odata.associationLink and @odata.nagivationLink properties such that the response payload looks as follows:

{
    "@odata.context": "http://localhost:5219/odata/$metadata#Customers/ODataAlternateKeySample.Models.GoldCustomer/$entity",
    "@odata.type": "#ODataAlternateKeySample.Models.GoldCustomer",
    "@odata.id": "http://localhost:5219/odata/Customers(1)/ODataAlternateKeySample.Models.GoldCustomer",
    "@odata.editLink": "Customers(1)/ODataAlternateKeySample.Models.GoldCustomer",
    "Id": 1,
    "Name": "Tom",
    "CountryOrRegion": null,
    "Passport": null,
    "SSN": "SSN-1-101",
    "Titles@odata.type": "#Collection(String)",
    "Titles": [ "abc", null, "efg" ],
    "Contact@odata.associationLink": "http://localhost:5219/odata/Customers(1)/ODataAlternateKeySample.Models.GoldCustomer/Contact/$ref",
    "Contact@odata.navigationLink": "http://localhost:5219/odata/Customers(1)/ODataAlternateKeySample.Models.GoldCustomer/Contact"
}

@xuzhg

xuzhg commented Jan 31, 2023

Copy link
Copy Markdown
Member

@gathogojr Is it part of #798 ?

@gathogojr

Copy link
Copy Markdown
Contributor Author

@gathogojr Is it part of #798 ?

@xuzhg I didn't realize the customer had created a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@odata.id and other links are wrong if type is derived and has a navigation property

3 participants