Reputation: 41
This worked in Odata v6 but is now throwing an error in v7
$filter=CreateDateUtc gt 2014-06-23
In the above example CreateDateUtc would be a DateTimeOffset. I'm not sure what changed between versions that broke this functionality.
The error returned is "The query specified in the URI is not valid. No coercion operator is defined between types 'Microsoft.OData.Edm.Date' and 'System.Nullable`1[System.DateTimeOffset]'."
I tried upgrading to v7.5 but that didn't fix the issue.
I'm fine with writing custom code to handle this but I'm not exactly where I should start. I tried using a custom ODataUriResolver where I override the PromoteBinaryOperandTypes method but that didn't seem to work. Is the best way to make a custom EnableQueryAttribute where I modify the actual query?
Any guidance would be extremely helpful.
Upvotes: 4
Views: 697
Reputation: 2907
OData can't convert the constant to a datetime because it expects a full datetime constant :
$filter=CreateDateUtc gt 2014-06-23T00:00:00Z
Or you could use the date() function to convert your property to a date :
$filter=date(CreateDateUtc) gt 2014-06-23
Upvotes: 3