按 DateTimeOffset 的 Wcf Web API 过滤器

发布于 2024-12-19 00:20:26 字数 1391 浏览 1 评论 0原文

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

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

但是我收到的只是一条错误消息:

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

过滤似乎工作正常,因为这样过滤器返回请求的用户

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 过滤器一起使用,所以我是否错误地创建了过滤器?或者还有其他的事情在起作用吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千纸鹤带着心事 2024-12-26 00:20:26

你尝试过

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')

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')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文