Why does oData V4 not order on datetime?

送分小仙女□ 提交于 2019-12-25 06:19:05

问题


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

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:

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


回答1:


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

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




回答2:


This is an Issue, and it's been fixed in 5.6.0 beta1, please try it, if the issue still exist, please file an issue for us :).



来源:https://stackoverflow.com/questions/30014227/why-does-odata-v4-not-order-on-datetime

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