Search code examples
odataasp.net-web-api2

Does OData v4 not support Nullable<DateTime>?


Server Error in '/' Application.


The type 'System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' of property 'DataAlteracaoDate' in the 'WebAPIOData.Models.Categoria' type is not a supported type. Parameter name: navigationProperty

Stack Trace:

[ArgumentException: The type 'System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' of property 'DataAlteracaoDate' in the 'WebAPIOData.Models.Categoria' type is not a supported type. Parameter name: navigationProperty]
System.Web.OData.Builder.EntityTypeConfiguration.AddNavigationProperty(PropertyInfo navigationProperty, EdmMultiplicity multiplicity, Boolean containsTarget) +1054
System.Web.OData.Builder.EntityTypeConfiguration.AddNavigationProperty(PropertyInfo navigationProperty, EdmMultiplicity multiplicity) +47
System.Web.OData.Builder.ODataConventionModelBuilder.MapEntityType(EntityTypeConfiguration entity) +447
System.Web.OData.Builder.ODataConventionModelBuilder.MapType(StructuralTypeConfiguration edmType) +120
System.Web.OData.Builder.ODataConventionModelBuilder.MapTypes() +104
System.Web.OData.Builder.ODataConventionModelBuilder.GetEdmModel() +195 WebAPIOData.WebApiConfig.GetModel() in c:\Projetos\HND022Git\SmartSales\Implementacao\Codigo\Web\SmartSales\WebAPIOData\App_Start\WebApiConfig.cs:65 WebAPIOData.WebApiConfig.Register(HttpConfiguration config) in c:\Projetos\HND022Git\SmartSales\Implementacao\Codigo\Web\SmartSales\WebAPIOData\App_Start\WebApiConfig.cs:25 WebAPIOData.WebApiApplication.Application_Start() in c:\Projetos\HND022Git\SmartSales\Implementacao\Codigo\Web\SmartSales\WebAPIOData\Global.asax.cs:21

[HttpException (0x80004005): The type 'System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' of property 'DataAlteracaoDate' in the 'WebAPIOData.Models.Categoria' type is not a supported type. Parameter name: navigationProperty]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9936761
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

[HttpException (0x80004005): The type 'System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' of property 'DataAlteracaoDate' in the 'WebAPIOData.Models.Categoria' type is not a supported type. Parameter name: navigationProperty]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9915300 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

My class has a property "DataAlteracaoDate" of type Nullable<DateTime>

I'm setting the entity on ODataModelBuilder on this way:

builder.EntitySet<Categoria>("Categorias").EntityType.HasKey(t => t.IdCategoria);

I'm using the lasted version for Prerelease Microsoft.AspNet.OData.5.2.0-rc-140512 in my app.

Does anybody has any suggestion?


Solution

  • DateTime is no longer supported in OData v4. What it supports is DateTimeOffset, either nullable or not.