WCF Web API通过DateTimeOffset进行过滤 [英] Wcf Web API filter by DateTimeOffset

查看:96
本文介绍了WCF Web API通过DateTimeOffset进行过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在使用WCF Web API Preview 5,并试图过滤LastModifiedDate大于或等于提供的datetimeoffset的用户列表:

I am currently using WCF Web API Preview 5 and am trying to filter a list of users where the LastModifiedDate is greater than or equal to the provided datetimeoffset:

 http://api.myapp.com/users?$filter=LastModifiedDate ge datetimeoffset'2011-06-01T14:03:00+00:00Z'

但是我得到的只是一个错误:

However all I am getting is an error saying:

Microsoft.ApplicationServer.Query.ParseException: '.' or '(' expected (at index 34)

由于此过滤器返回了所请求的用户,因此过滤器似乎工作正常

The filtering seems to be working fine as this filter returns the requested user

http://api.myapp.com/users?$filter=UserId eq 1

-- XML Response
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfUser xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <User>
    <ExtensionData />
    <CreateDate />
    <CreatedById>1</CreatedById>
    <IsDeleted>false</IsDeleted>
    <LastModifiedById>1</LastModifiedById>
    <LastModifiedDate />
    <Name>Joe</Name>
    <UserId>1</UserId>
  </User>
</ArrayOfUser>

-- JSON Response
[
  {
    "CreateDate":
    {
      "DateTime":"\/Date(1306481778297)\/",
      "OffsetMinutes":0
    },
    "CreatedById":1,
    "IsDeleted":false,
    "LastModifiedById":1,
    "LastModifiedDate":
    {
      "DateTime":"\/Date(1306936979717)\/",
      "OffsetMinutes":0
    },
    "Name":"Joe",
    "UserId":1
  }
]

只是无法使其与DateTimeOffset过滤器一起使用,所以我会错误地创建过滤器吗?还是还有其他东西在玩?

Just cannot get it working with the DateTimeOffset filter so am I creating the filter incorrectly? Or is there something else at play?

推荐答案

您尝试过

http://api.myapp.com/users?$filter=LastModifiedDate ge datetimeoffset('2011-06-01T14:03:00+00:00Z')

http://api.myapp.com/users?$filter=LastModifiedDate ge (datetimeoffset'2011-06-01T14:03:00+00:00Z')

这篇关于WCF Web API通过DateTimeOffset进行过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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