AspNetCoreOData
AspNetCoreOData copied to clipboard
Support for case method call
According to OData documentation (https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_case) we should be able to use case method call. I tried this with Microsoft.AspNetCore.OData version 8.0.11.
Client called this URL
http://localhost:60600/odata/Search?$select=name&$compute=case(indexof(name, 'test') eq -1:10000,true:indexof(name, 'test')) as rank&$orderby=rank asc
it returns following error
{
"error": {
"code": "",
"message": "The query specified in the URI is not valid. ')' or ',' expected at position 32 in 'case(indexof(name, 'test') eq -1:10000,true:indexof(name, 'test')) as rank'.",
"details": [],
"innererror": {
"message": "')' or ',' expected at position 32 in 'case(indexof(name, 'test') eq -1:10000,true:indexof(name, 'test')) as rank'.",
"type": "Microsoft.OData.ODataException",
"stacktrace": " at Microsoft.OData.UriParser.FunctionCallParser.ParseArgumentListOrEntityKeyList(Action restoreAction)\r\n at Microsoft.OData.UriParser.FunctionCallParser.TryParseIdentifierAsFunction(QueryToken parent, QueryToken& result)\r\n at Microsoft.OData.UriParser.IdentifierTokenizer.ParseIdentifier(QueryToken parent)\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParsePrimary()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseInHas()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseUnary()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseMultiplicative()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseAdditive()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseComparison()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseLogicalAnd()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseLogicalOr()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseExpression()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseComputeExpression()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseCompute(String compute)\r\n at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseComputeImplementation(String compute, ODataUriParserConfiguration configuration, ODataPathInfo odataPathInfo)\r\n at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseCompute()\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)"
}
}
}
seems like case is not supported
any update on this? Looking for a coalesce type function and this seemed to be it, e.g.
{ "createdDate": "{{datetime}}", "modifiedDate": "{{datetime}}" }
want a computed value that outputs modifiedDate if not null, else createdDate, tried
$compute=case(modifiedDate ne null:modifiedDate, true:createdDate) as date&$select=date
get error
{
"error": {
"code": "",
"message": "The query specified in the URI is not valid. ')' or ',' expected at position 25 in 'case(modifiedDate ne null:modifiedDate, true:createdDate) as date'.",
"details": [],
"innererror": {
"message": "')' or ',' expected at position 25 in 'case(modifiedDate ne null:modifiedDate, true:createdDate) as date'.",
"type": "Microsoft.OData.ODataException",
"stacktrace": " at Microsoft.OData.UriParser.FunctionCallParser.ParseArgumentListOrEntityKeyList(Action restoreAction)\r\n at Microsoft.OData.UriParser.FunctionCallParser.TryParseIdentifierAsFunction(QueryToken parent, QueryToken& result)\r\n at Microsoft.OData.UriParser.IdentifierTokenizer.ParseIdentifier(QueryToken parent)\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParsePrimary()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseInHas()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseUnary()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseMultiplicative()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseAdditive()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseComparison()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseLogicalAnd()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseLogicalOr()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseExpression()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseComputeExpression()\r\n at Microsoft.OData.UriParser.UriQueryExpressionParser.ParseCompute(String compute)\r\n at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseComputeImplementation(String compute, ODataUriParserConfiguration configuration, ODataPathInfo odataPathInfo)\r\n at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseCompute()\r\n at Microsoft.AspNetCore.OData.Query.Validator.ComputeQueryValidator.Validate(ComputeQueryOption computeQueryOption, 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)"
}
}
}
I don't think the feature label is correct, seems like a bug to me
I don't think the feature label is correct, seems like a bug to me
I disagree. If this was never implemented, never supported and never documented as supported, it can't be a bug.
Please keep in mind that the OData spec and the .NET implementation are 2 separate things. There is a lot of stuff in the Spec that the .NET implementation doesn't yet support.
I don't think the feature label is correct, seems like a bug to me
I disagree. If this was never implemented, never supported and never documented as supported, it can't be a bug.
Please keep in mind that the OData spec and the .NET implementation are 2 separate things. There is a lot of stuff in the Spec that the .NET implementation doesn't yet support.
The blog post associated with adding $compute says you can use built in functions, one of which is case, so I would expect it to work, hence a bug not feature
The blog post associated with adding $compute says you can use built in functions, one of which is
case, so I would expect it to work, hence a bug not feature
Oh that's fair enough. I stand corrected and agree then.
Hi, any update on a fix for this? I may have time to look myself, depends on work priorities though. Any hints on where to look would be appreciated. Thanks
I'm in the same boat, trying to perform a null coalescing sort across two fields. Does anyone have a working solution?
I'm in the same boat too. I want to multiply a value by minus, according another boolean value. I think the best way to achieve this using "compute and case" together.