Handling Dates with OData v4, EF6 and Web API v2.2

前端 未结 4 412
孤城傲影
孤城傲影 2020-12-10 16:14

I\'m in the midst of upgrading from v1-3 to v4, but I\'ve run into a few problems.

My understanding is that DateTime is unsupported, and I have to always use DateTim

4条回答
  •  有刺的猬
    2020-12-10 16:53

    For anyone coming to this in the future, the OData v4 team have fixed this issue.

    [Column(TypeName = "date")]
    public DateTime Birthday { get; set; }
    

    This will now auto-resolve to Edm.Date.

    If you are like me and are doing date type by convention, you have to manually declare the properties as dates lest they be auto-resolved as DateTimeOffset. OData currently does not allow you to add your own conventions.

    customer.Property(c => c.Birthday).AsDate();
    

    http://odata.github.io/WebApi/#12-01-DateAndTimeOfDayWithEF

提交回复
热议问题