gpt4 book ai didi

.net - 如何将 DateTimeOffset 参数传递给 oData 函数

转载 作者:行者123 更新时间:2023-12-04 02:15:06 25 4
gpt4 key购买 nike

我有一个名为 GetForPeriod 的 odata 函数定义为:

        var getForPeriod =
builder.EntityType<EventModel>()
.Collection
.Function("GetForPeriod")
.ReturnsCollection<EventModelSummary>();
getForPeriod.Parameter<DateTimeOffset>("from");
getForPeriod.Parameter<DateTimeOffset>("to");

所以要从函数中获取结果,我需要调用:

http://localhost:17257/odata/Events/Default.GetForPeriod(from=2015-12-27T00:00:00-06:00,to=2016-02-06T00:00:00- 06:00)

但我不断收到错误信息:

A potentially dangerous Request.Path value was detected from the client (:).

问题是日期,好像我有http://localhost:17257/odata/Events/Default.GetForPeriod(from=null,to=null)我收到一条错误消息,指出它无法将 null 转换为 DateTimeOffset(这是有道理的)。

我尝试将 from 中的冒号 (:) 和两个值替换为 %3A,但我仍然遇到相同的危险路径错误。

有趣的是,如果我使用日期过滤器调用事件的读取路径,它就可以正常工作。http://localhost:17257/odata/Events?$filter=ScheduledDate%20ge%202015-12-27T00:00:00-06:00%20and%20ScheduledDate%20le%202016-02-06T00:00: 00-06:00

我应该如何调用 OData 函数,该函数采用参数的日期时间偏移量?

最佳答案

你能试试函数参数别名吗?

来自 OData 规范:

可以使用参数别名代替函数调用的内联参数。别名的值使用参数别名的名称指定为单独的查询选项。

示例 76:通过函数 import EmployeesByManager 调用 Sales.EmployeesByManager 函数,为 ManagerID 参数传递 3

http://host/service/EmployeesByManager(ManagerID=@p1)?@p1=3

https://github.com/OData/WebApi/issues/204 上跟踪了相同的问题

谢谢。

关于.net - 如何将 DateTimeOffset 参数传递给 oData 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34755423/

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