$orderby fails on derived type property
@gathogojr is already working on this.
Since Jan 23, 2024.
- Dominant language
- C#
- Stars
- 505
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
Assemblies affected
ASP.NET Core OData 8.2.3
Describe the bug
$orderby fails on derived type property
Reproduce steps
Submit a request to obtain a navigation property, ordered by a property of a derived type.
Data Model
public class Company
{
public int Id { get; set; }
public ICollection<Customer> Customers { get; set; }
}
public class Customer
{
public int Id { get; set; }
}
public class PremiumCustomer : Customer
{
public int Nr { get; set; }
}
EDM (CSDL) Model
<?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="DataApi.Models" xmlns="http://docs.oasis-open.org/odata/ns/edm">
<EntityType Name="Customer">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int32" Nullable="false" />
</EntityType>
<EntityType Name="Company">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int32" Nullable="false" />
<NavigationProperty Name="Customers" Type="Collection(DataApi.Models.Customer)" />
</EntityType>
<EntityType Name="PremiumCustomer" BaseType="DataApi.Models.Customer">
<Property Name="Nr" Type="Edm.Int32" Nullable="false" />
</EntityType>
</Schema>
<Schema Namespace="Default" xmlns="http://docs.oasis-open.org/odata/ns/edm">
<EntityContainer Name="Container">
<EntitySet Name="Customers" EntityType="DataApi.Models.Customer" />
<EntitySet Name="Companies" EntityType="DataApi.Models.Company">
<NavigationPropertyBinding Path="Customers" Target="Customers" />
</EntitySet>
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
Request/Response
~Companies(3)/Customers?$orderby=DataApi.Models.PremiumCustomer/Nr desc
{
"error": {
"code": "",
"message": "The query specified in the URI is not valid. Syntax error at position 39 in 'DataApi.Models.PremiumCustomer/Nr desc;'.",
"details": [],
"innererror": {
"message": "Syntax error at position 39 in 'DataApi.Models.PremiumCustomer/Nr desc;'.",
"type": "Microsoft.OData.ODataException",
"stacktrace": " at Microsoft.OData.UriParser.ExpressionLexer.ValidateToken(ExpressionTokenKind t)\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseOrderBy(String orderBy)\r\n at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseOrderByImplementation(String orderBy, ODataUriParserConfiguration configuration, ODataPathInfo odataPathInfo)\r\n at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseOrderBy()\r\n at Microsoft.AspNetCore.OData.Query.OrderByQueryOption.get_OrderByClause()\r\n at Microsoft.AspNetCore.OData.Query.Validator.OrderByQueryValidator.Validate(OrderByQueryOption orderByOption, ODataValidationSettings validationSettings)\r\n at Microsoft.AspNetCore.OData.Query.Validator.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings)\r\n at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.ValidateQuery(HttpRequest request, ODataQueryOptions queryOptions)\r\n at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.OnActionExecuting(ActionExecutingContext actionExecutingContext)"
}
}
}
Expected behavior
Result is ordered by PremiumCustomer.Nr
Additional context
I see the same issue as in: https://github.com/OData/WebApi/issues/861, but I don't see it is fixed on AspNetCoreOData.
I tried ~Companies(3)/Customers/DataApi.Models.PremiumCustomer?$orderby=Nr desc, but got 404.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.