0

I have a working application in ASP.NET Web API 2 (not Core). The app includes several datetime columns in the database (DateTime in C#). Until now I've been using OData 5.9 in the app and I've been able to use filter those columns in $filter with ISO 8601 date strings. I used the suggestion in this question to add config.SetTimeZoneInfo(TimeZoneInfo.Utc); to my config and this worked great.

Fast forward to today. I just upgraded the project to OData 7.4. Everything went smoothly except for the DateTime properties. I can no longer use those properties in my $filter without getting this error

Microsoft.Data.SqlClient.SqlException: Conversion failed when converting date and/or time from character string.

Is there some new configuration change I need to make to continue working with DateTime properties in OData 7.4?

just.another.programmer
  • 8,579
  • 8
  • 51
  • 90
  • Are the dates null? It may be that OData fixed a bug where null dates were allowed and now not allowed. – jdweng Jun 18 '20 at 17:37
  • @jdweng I've tried it with `DateTime?` and `DateTime` properties. `DateTime?` gives the error in the question, `DateTime` gives a cast error. Why would a nullable date not be allowed? – just.another.programmer Jun 18 '20 at 18:14
  • DataTime is c# cannot be null but in DataBase is can be null. The question mark in c# for DateTime is not valid. Ask Microsoft why a date cannot be null. The best you can get is the default 1/1/1. – jdweng Jun 18 '20 at 19:24

0 Answers0