AspNetCoreOData icon indicating copy to clipboard operation
AspNetCoreOData copied to clipboard

DateOnly quering not working

Open alc86 opened this issue 2 years ago • 11 comments

Hi,

We are currently working on a project with .Net 6, EF Core 6, Npgsql provider and AspNetCore.OData. There is still a problem with the Expression generation because the expression tree contains elements with 'System.Nullable`1[Microsoft.OData.Edm.Date]'. I think these elements should be of type DateOnly.

alc86 avatar Mar 31 '22 08:03 alc86

There is still a problem with the Expression generation because the expression tree contains elements with 'System.Nullable`1[Microsoft.OData.Edm.Date]'. I think these elements should be of type DateOnly.

What problem? Can you elaborate a bit more and include a repro of the issue?

I think these elements should be of type DateOnly.

I assume you mean OData's own custom date only class and not .NET6's type, right? .NET6 DateOnly and TimeOnly are not currently supported by OData.

  • https://github.com/OData/odata.net/issues/2293

julealgon avatar Mar 31 '22 12:03 julealgon

I thought this is already implemented https://github.com/OData/ModelBuilder/issues/22

alc86 avatar Apr 01 '22 08:04 alc86

HI! any news?

max1997dc avatar Jun 28 '23 17:06 max1997dc

Seems to be working in regular filter/select, but when trying to group by "DateOnly" field it throws "System.NullReferenceException: Object reference not set to an instance of an object."

Can anyone suggest a workaround to this issue for now? Maybe way to cast to string in OData model builder? Or force it to think its a DateTime?

String is: "Results?apply=filter(projectId eq 1982)/groupby((projectId,answerText,responseDate),aggregate(weight with sum as sumWeight,id with countdistinct as count))"

That response date is causing the problem. Replacing it with any other column (including datetime) works just fine. But when its DateOnly I get that null ref.

NikAtIdeally avatar Nov 09 '23 01:11 NikAtIdeally

Getting this error when using DateOnly and Time Only The LINQ expression 'DbSet<Entity_fdfcca13206d4762a7a17bdff77201cc>() .Where(e => e.WorkDate.Value.Year * 10000 + e.WorkDate.Value.Month * 100 + e.WorkDate.Value.Day == __p_0)' could not be translated. Either rewrite the query in a form that can be translated,

or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

EF Core 7 Net Core 6

imaa avatar Jan 05 '24 15:01 imaa

Similar error when I do a patch request. I am required to provide date only eg "2022-01-20". If I provide a datetime in the JSON eg "0001-02-24T00:00:00.000Z" I get an error saying : System.NullReferenceException: Object reference not set to an instance of an object.

rsgilbert avatar Feb 28 '24 16:02 rsgilbert

Hello, OData Team.

Question #1. What's the current support of DateOnly and TimeOnly types in the latest ASP.NET Core Web API/OData versions (primarily for .NET 8+ and EF Core 8+) and limitations? Question #2. If OData does not support these newest types as of now, what is your vision/plans for the scenarios our customers having below?

Motivation: Because of the EF Core 8 breaking change and a huge adoption of EF Core 8 by developers after .NET 8 release last year (a tweet by MSFT), we at DevExpress want to support these newest types for the following CRUD scenarios:

  • DevExpress UI components for Blazor, JavaScript, WinForms, and WPF primarily (maybe .NET MAUI, WinUI later) when binding to EF Core 8 data sources (we have no show-stoppers here so far).
  • OData-based data sources and components for various UI and non-UI platforms (for instance, our JavaScript integration, our Blazor integration, our cross-platform Web API Service, to name just a few).
  • As you may understand, these enhancements also help our mutual goal with further .NET 8+, ASP.NET Core /Blazor, .NET MAUI, adoption/growth.

I saw another issue https://github.com/OData/ModelBuilder/issues/22, but wanted to verify it directly with your team.

Thanks, Dennis Garavsky Product Manager at https://www.devexpress.com/ [email protected]

dennis-garavsky avatar Mar 07 '24 12:03 dennis-garavsky

@habbes @mikepizzo ☝️

julealgon avatar Mar 07 '24 13:03 julealgon

Hi, any news?

ThomasHeijtink avatar Mar 22 '24 15:03 ThomasHeijtink

I am getting the following error when trying to filter on a sql nullable 'Date' column (DateOnly? type in .NET):

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)
FilterBinder.BindFilter(QueryToken filter)

Is there a solution at the moment, or do we have to wait for a fix in the repo?

ArnaudB88 avatar Mar 28 '24 20:03 ArnaudB88