Asp.net 使用oData V4计算最大日期

Asp.net 使用oData V4计算最大日期,asp.net,entity-framework-6,odata,Asp.net,Entity Framework 6,Odata,我正在尝试获取上次创建带有各种状态代码的记录的日期。我提出这个问题: http://localhost/FTPOrdersoDataService/odata/FTP_ORDER_STATUS_LOG?$apply=groupby((STATUS), aggregate(FTP_ORDERS_ID with max as lastCreated)) 返回以下错误:” 然后它就可以正常工作了,显然问题出在CREATEDDATE字段上。CREATEDDATE在Oracle中定义为TIMESTAMP

我正在尝试获取上次创建带有各种状态代码的记录的日期。我提出这个问题:

http://localhost/FTPOrdersoDataService/odata/FTP_ORDER_STATUS_LOG?$apply=groupby((STATUS), aggregate(FTP_ORDERS_ID with max as lastCreated))
返回以下错误:”

然后它就可以正常工作了,显然问题出在CREATEDDATE字段上。CREATEDDATE在Oracle中定义为TIMESTAMP(6),在我的EF模型中定义为DateTime

让max(和其他聚合函数)处理日期有什么秘密吗

在Microsoft.AspNet.OData.7.4.1中测试

过去这方面存在问题,但是OData实现已经发展,现在您可以使用以下查询语法将字段强制转换为标准
EnableQueryAttribute
支持的类型:

聚合(cast(CREATEDDATE,Edm.DateTimeOffset),最大值为上次创建的值)


这似乎是OData/WebAPI的已知错误。请尝试使用DateTimeOffset而不是DateTime
{
"error": {
"code": "",
"message": "An error has occurred.",
"innererror": {
"message": "Argument types do not match",
"type": "System.ArgumentException",
"stacktrace": "   at System.Linq.Expressions.Expression.Bind(MemberInfo member, Expression expression)\r\n   at System.Web.OData.Query.Expressions.AggregationBinder.BindSelect(IQueryable grouping)\r\n   at System.Web.OData.Query.ApplyQueryOption.ApplyTo(IQueryable query, ODataQuerySettings querySettings)\r\n   at System.Web.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query, ODataQuerySettings querySettings)\r\n   at System.Web.OData.EnableQueryAttribute.ExecuteQuery(Object response, HttpRequestMessage request, HttpActionDescriptor actionDescriptor, ODataQueryContext queryContext)\r\n   at System.Web.OData.EnableQueryAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.OnActionExecutedAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}
}
}
http://localhost/FTPOrdersoDataService/odata/FTP_ORDER_STATUS_LOG?$apply=groupby((STATUS), aggregate(FTP_ORDERS_ID with max as lastCreated))
http://localhost/FTPOrdersoDataService/odata/FTP_ORDER_STATUS_LOG?$apply=groupby((STATUS), aggregate(cast(CREATEDDATE, Edm.DateTimeOffset) with max as lastCreated))