Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter on nullable DateOnly seems not supported #2912

Open
ArnaudB88 opened this issue Mar 29, 2024 · 4 comments
Open

Filter on nullable DateOnly seems not supported #2912

ArnaudB88 opened this issue Mar 29, 2024 · 4 comments

Comments

@ArnaudB88
Copy link

I want to filter on a nullable DateOnly type field. Currently this throws an exception.

Assemblies affected

Microsoft.OData.Core.dll v7.20

Reproduce steps

  • have a sql database with a table with a nullable Date field
  • this is mapped to a .NET class with a property type DateOnly? since .NET8 is used
  • execute a query which filters on the nullable DateOnly field eg StartDate ge 2024-03-29

Expected result

Query would return a result

Actual result

I am getting the following error:

Microsoft.OData.ODataException: A binary operator with incompatible types was detected. Found operand types 'System.Nullable_1OfDateOnly' and 'Edm.Date' for operator kind 'GreaterThanOrEqual'.

  Stack Trace: 
BinaryOperatorBinder.PromoteOperandTypes(BinaryOperatorKind binaryOperatorKind, SingleValueNode& left, SingleValueNode& right, TypeFacetsPromotionRules facetsPromotionRules)
ODataUriResolver.PromoteBinaryOperandTypes(BinaryOperatorKind binaryOperatorKind, SingleValueNode& leftNode, SingleValueNode& rightNode, IEdmTypeReference& typeReference)
StringAsEnumResolver.PromoteBinaryOperandTypes(BinaryOperatorKind binaryOperatorKind, SingleValueNode& leftNode, SingleValueNode& rightNode, IEdmTypeReference& typeReference)
BinaryOperatorBinder.BindBinaryOperator(BinaryOperatorToken binaryOperatorToken)
MetadataBinder.BindBinaryOperator(BinaryOperatorToken binaryOperatorToken)
MetadataBinder.Bind(QueryToken token)
...

Additional detail

This is possibly related with the feature request #2293

@xuzhg
Copy link
Member

xuzhg commented Apr 1, 2024

@ArnaudB88 'DateOnly' and 'TimeOnly' are two new C# types added since .NET 6. ODL hasn't supported them by default owing to the target framework setting. We'd like to enable it in the next major version. Before that, ODL has its own 'Date' and 'TimeOfDay' types that you can use.

@gathogojr
Copy link
Contributor

Hi @ArnaudB88. This is a known feature gap. I'll go ahead and close this issue and use #2293 to track the work required to support the DateOnly and TimeOnly.

@robbaman
Copy link

Hi @ArnaudB88. This is a known feature gap. I'll go ahead and close this issue and use #2293 to track the work required to support the DateOnly and TimeOnly.

Hi @gathogojr it seems the item you're referring to has been around for more than two years and still there is no support for the DateOnly (and TimeOnly) types in a query filter. We've gone and create a copy of the code for our private feed that simply adds two additional if-statements to the to the FormatRawLiteral of the LiteralFormatter class as I described here, but you can imaging having own copies of such public libraries is far from ideal.

#2293 (comment)

Is there any chance this can be added any time soon? I'd make a PR for just the change I made, but since this just fixes the NotSupportException when creating a filter this doesn't quite seem to cover the whole "Deprecate 'TimeOfDay' and 'Date' types in favor" case.

@xuzhg xuzhg reopened this Oct 9, 2024
@xuzhg
Copy link
Member

xuzhg commented Oct 9, 2024

#3078 supports the DateOnly and TimeOnly in OData.Core and We'd move forward to fully support it in OData.Client and OData Connected Service.

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

No branches or pull requests

4 participants