如何使用动态日期过滤oData调用? [英] How to filter oData call using dynamic date?

查看:83
本文介绍了如何使用动态日期过滤oData调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用URL进行AJAX调用,如下所示.

I'm making an AJAX call using URL as follows.

http://somecomputer/Service.svc/Method?$filter=SomeDate gt DateTime'2014-08-24'

这非常有效,并且此刻,我生成了一个字符串,描述了我的AJAX调用之前的日期.但是,我想知道是否可以在动态值上匹配日期,例如 today lastyear 或其他什么值.

This works perfectly and and the moment, I generate the string describing the date right before my AJAX call. However, I wonder if it's possible to match the date on dynamic values, such as today or lastyear or what not.

我在进行谷歌搜索时没有发现任何相关文档,因此可能无法实现,但是我仍然需要核实SO的智慧.

I haven't found any documentation of that when googling so probably it's not possible but I still need to check with the wisdom of SO.

推荐答案

是的,有可能.诸如now(),并且ODataLib已在其最新版本的URL解析器中支持该函数. (请参见此处的发行说明.)

Yes, it is possible. There is such thing as Built-in Query Functions in OData that you can use in query options to represent dynamic values. From the link you can see that there is this function now() under the "Date Functions" category and the ODataLib has already supported it in the URL parser of its latest version. (see the release notes here).

但是有两件事需要您注意:

But there are two things for you to note:

  1. ODataLib仅处理请求URL中此类功能的解析,其实际逻辑需要由服务实现者进一步实现.
  2. 根据OData V3协议的查询(
  1. ODataLib only deals with the parsing of such functions in request URLs, the actual logic of it needs to be further implemented by the service implementers.
  2. According to the look up of the OData V3 protocol (section 10.2.3.1.2 on this page), V3 doesn't have such dynamic built-in query functions.

这篇关于如何使用动态日期过滤oData调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆