cast from string to int doesn't work
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 505
- Forks
- 186
- PR merge metrics
- No merged PRs in 30d
Description
OData 8.2.3
I'm trying something like:
http://localhost:5066/odata/Table?$count=true&$top=100&$orderby=cast(source_id,Edm.Int32)
And I've got this error:
{
"error": {
"code": "",
"message": "The query specified in the URI is not valid. Only ordering by properties is supported for non-primitive collections. Expressions are not supported.",
"details": [],
"innererror": {
"message": "Only ordering by properties is supported for non-primitive collections. Expressions are not supported.",
"type": "Microsoft.OData.ODataException",
"stacktrace": " at Microsoft.AspNetCore.OData.Query.OrderByPropertyNode..ctor(OrderByClause orderByClause)\n at Microsoft.AspNetCore.OData.Query.OrderByNode.CreateCollection(OrderByClause orderByClause)\n at Microsoft.AspNetCore.OData.Query.OrderByQueryOption.get_OrderByNodes()\n at Microsoft.AspNetCore.OData.Query.Validator.OrderByQueryValidator.Validate(OrderByQueryOption orderByOption, ODataValidationSettings validationSettings)\n at Microsoft.AspNetCore.OData.Query.Validator.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings)\n at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.ValidateQuery(HttpRequest request, ODataQueryOptions queryOptions)\n at Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.OnActionExecuting(ActionExecutingContext actionExecutingContext)"
}
}
}
This is my field:
[Key]
[ODataAnnotation(ODataMetadataTerm.Comparable)]
public string source_id { get; set; }
and my OData config as well:
public static ODataOptions AddODataModel(this ODataOptions? options)
{
options ??= new ODataOptions();
options.EnableQueryFeatures(3000);
options.SkipToken().AddRouteComponents(routePrefix: ODataConfiguration.RoutePrefix, model: EdmModel, services =>
{
services.AddSingleton<ISearchBinder, SearchBinder>();
services.AddSingleton<ODataBatchHandler>(GetBatchHandler());
services.AddSingleton<SkipTokenHandler, CustomSkipTokenHandler>();
});
options.RouteOptions.EnableNonParenthesisForEmptyParameterFunction = true;
options.EnableAttributeRouting = true;
return options;
}
Is it even possible to do such operations?
Thanks!
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.
Research direction
Reproduce the OData 8.2.3 request using the shown source_id model property and $orderby=cast(...) query. Start with the stack-trace entry points OrderByPropertyNode, OrderByNode, OrderByQueryValidator, and EnableQueryAttribute to determine whether the validation path supports this expression; done means the supported behavior or required change is established and covered by an appropriate test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100