gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 07:42:28 25 4
gpt4 key购买 nike

我正在尝试获取上次创建具有各种状态代码的记录的日期。我发出这个查询:

http://localhost/FTPOrdersoDataService/odata/FTP_ORDER_STATUS_LOG?$apply=groupby((STATUS), aggregate(FTP_ORDERS_ID with max as lastCreated))

返回以下错误":

{
"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))

然后它可以正常运行,所以很明显问题出在 CREATEDDATE 字段上。 CREATEDDATE 在 Oracle 中定义为 TIMESTAMP(6),在我的 EF 模型中定义为 DateTime。

是否有使 max(和其他聚合函数)与日期一起使用的秘诀?

最佳答案

Tested in Microsoft.AspNet.OData.7.4.1

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

聚合(cast(CREATEDDATE,Edm.DateTimeOffset),最大值为 lastCreated)

http://localhost/FTPOrdersoDataService/odata/FTP_ORDER_STATUS_LOG?$apply=groupby((STATUS), aggregate(cast(CREATEDDATE, Edm.DateTimeOffset) with max as lastCreated))

关于asp.net - 使用 oData V4 计算最大日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44523961/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com