WCF WebApi IQueryable 不适用于 DateTime 属性
我无法通过 DateTime 属性查询任何对象。
public class MyModel
{
public int Id { get; set; }
public DateTime TimeStamp { get; set; }
}
[ServiceContract]
public class BuildJobApi
{
[WebGet]
public IQueryable<MyModel> GetMyModels()
{
return _service.GetMyModels(); // IQueryable<MyModel>
}
}
我尝试使用 WCF WebApi v0.5.0 和 0.6.0,两者都抛出错误消息。
这是(由 WebApi)生成的用于按 Id 查询的 URL(有效):
/api/models?$filter=(Id eq 100)
这是生成的用于按 TimeStamp 查询的 URL(无效):
/api/models?$filter=TimeStamp ge DateTime'2012-02-22T00:00:00'
我还可以按日期部分查询(有效):
/api/models?$filter=(year(ExceptionDateTime) eq 2012)
确切的错误消息是 500/Internal服务器错误。带有消息:
The server encountered an error processing the request. See server logs for more details.
问:是否可以执行任何操作来查询 DateTime 属性,而无需单独查询每个部分?
I'm unable to query any object by the DateTime properties.
public class MyModel
{
public int Id { get; set; }
public DateTime TimeStamp { get; set; }
}
[ServiceContract]
public class BuildJobApi
{
[WebGet]
public IQueryable<MyModel> GetMyModels()
{
return _service.GetMyModels(); // IQueryable<MyModel>
}
}
I tried using WCF WebApi v0.5.0 and 0.6.0, both are throwing error messages.
Here's the URL generated (by WebApi) to query by Id (works):
/api/models?$filter=(Id eq 100)
Here's the URL generated to query by TimeStamp (doesn't work):
/api/models?$filter=TimeStamp ge DateTime'2012-02-22T00:00:00'
I can also query by date part (works):
/api/models?$filter=(year(ExceptionDateTime) eq 2012)
The exact error message is 500/Internal Server Error. With the message:
The server encountered an error processing the request. See server logs for more details.
Q: Is there anything that can be done to query the DateTime properties without querying each part separately?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尽量避免序列化
DateTime
,为此使用字符串。例如:
“o”
表示 ISO 8601 格式(区域性不变、稳定格式)。Try to avoid serializing
DateTime
, use string for this.eg:
the
"o"
is for the ISO 8601 format (culture invariant, stable format).