Training
Module
Work with Microsoft Dataverse Web API - Training
Discover how to work with the Dataverse Web API, including authorizing with OAuth and using OData to query data.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies To:# OData WebApi v7 for aspnet webapi supported OData AspNet WebApi V7# OData Webapi for Webapi supported OData AspNet WebApi V6
This sample will introduce how to support DateTime type in Web API OData V4.
OData V4 doesn't include DateTime as primitive type. Web API OData V4 uses DateTimeOffset to represent the DateTime. For example, if user defines a model as:
public class Customer
{
public int Id { get; set; }
public DateTime Birthday { get; set; }
}
The metadata document for Customer entity type will be:
<EntityType Name="Customer">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int32" Nullable="false" />
<Property Name="Birthday" Type="Edm.DateTimeOffset" Nullable="false" />
</EntityType>
By Default, converting between DateTimeOffset and DateTime will lose the Time Zone information. Therefore, Web API provides a API to config the Time Zone information on server side. For example:
HttpConfiguration configuration = ...
TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"); // -8:00
configuration.SetTimeZoneInfo(timeZoneInfo);
Since Web API OData 5.6, it supports to filter on DateTime type. For example:
GET ~/Customers?$filter=Birthday lt cast(2015-04-01T04:11:31%2B08:00,Edm.DateTimeOffset)
GET ~/Customers?$filter=year(Birthday) eq 2010
Since Web API OData 5.6, it supports to orderby on DateTime type. For example:
GET ~/Customers?$orderby=Birthday
GET ~/Customers?$orderby=Birthday desc
Training
Module
Work with Microsoft Dataverse Web API - Training
Discover how to work with the Dataverse Web API, including authorizing with OAuth and using OData to query data.