为什么oData V4不能在日期时间订购? [英] Why does oData V4 not order on datetime?

查看:102
本文介绍了为什么oData V4不能在日期时间订购?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Web API 2.2和Entity Framework创建了oData V4端点.公开的模型类似于以下模型:

I've created a oData V4 endpoint with Web API 2.2 and Entity Framework. The model that is expose looks like the following model:

public class Items { 
    public int Id { get; set; }
    public string Name { get; set; }
    public DateTime CreatedOn { get; set; }
}

当我转到URL:/odata/Items时,它就像一个超级按钮.但是当我转到URL:/odata/Items?$ orderby = CreatedOn时,出现以下错误:

When I go to the URL: /odata/Items it works like a charm. But when I go to the URL: /odata/Items?$orderby=CreatedOn I get the following error:

'LINQ中不支持指定的类型成员'Kind' 实体.仅初始化器,实体成员和实体导航 属性."

'The specified type member 'Kind' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.'

推荐答案

OData v4不支持DateTime类型.您应该改用DateTimeOffset.这是因为如果您不指定时区,可能会发生问题.实际上,是否应该支持它都存在公开讨论.

OData v4 doesn't suport DateTime type. You should use DateTimeOffset instead. That's because of problems that can happen if you don't specify the time zone. In fact there is an open discussion if it shuld be supported or not.

请,请参阅以下参考文献:

Please, see this references:

  • SO Q&A: How to get Web API OData v4 to use DateTime
  • OData V4 service should support DateTime #136
  • OData V4 service should not support DateTime

如果您检查了这些问题,就会发现对DateTime的支持已添加到5.6.0 beta 1版本中.

If you check those issues, you'll find that support for DateTime has been added to version 5.6.0 beta 1.

这篇关于为什么oData V4不能在日期时间订购?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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