Wcf Web API filter by DateTimeOffset

送分小仙女□ 提交于 2019-12-11 09:22:20

问题


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
  }
]

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


回答1:


Did you try

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

or

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


来源:https://stackoverflow.com/questions/8313633/wcf-web-api-filter-by-datetimeoffset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!