The type System.DateTime is not a supported type. Change to use System.DateTimeOffset dotconnect entity-framework-6 mysql odata


We are creating a WebApi 2.2 service and are using the technologies listed above. Our backend datastore is MySql 5.6. We are using dotConnect for MySql to work with the data store. In the database, there is a RowVersion column with a type of Timestamp. In EF, I successfully generated the model, but I noticed that RowVersion is set to DateTime. When I run the WebApi, I get the following runtime exception, so I need to change the type to DateTimeOffset because Timestamp is not available.

In our application, we will use the RowVersion with ETags for concurrency handling. So, we will only read the RowVersion in our application; The database will automatically update the RowVersion whenever an insert or update happens.

I do not know how to correct this issue... Perhaps, there is some way to add an automatic type conversion so the RowVersion in the model is an Int64 and we automatically convert between the Int64 and Timestamp by sending the Timestamp.value to our application. We are only reading it, so this seems reasonable.

When I change the RowVersion to Int64 in the EF model and build the application, I receive the following error:

Error 1 Error 2019: Member Mapping specified is not valid. The type 'Edm.Int64[Nullable=True,DefaultValue=]' of member 'Version' in type 'Model.customer' is not compatible with 'Devart.Data.MySql.timestamp[Nullable=True,DefaultValue=,Precision=0]' of member 'Version' in type 'Model.Store.customers'. C:\PROJECTS\ServiceMySql\ServiceMySql\Models\Model.edmx 898 17 ServiceMySql

I'd really appreciate your help to figure out how to resolve this issue.

Thank you for your time and suggestions,


Exception mentioned at the beginning of this posting:

System.ArgumentException was unhandled by user code
HResult=-2147024809 Message=The type 'System.Nullable1[[System.DateTime, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' of property 'Version' in the 'XXXXServiceMySql.Models.customer' type is not a supported type. Change to use 'System.DateTimeOffset' or ignore this type by calling Ignore<XXXXServiceMySql.Models.customer>() on 'System.Web.OData.Builder.ODataModelBuilder'. Parameter name: navigationProperty Source=System.Web.OData
ParamName=navigationProperty StackTrace: at System.Web.OData.Builder.EntityTypeConfiguration.AddNavigationProperty(PropertyInfo navigationProperty, EdmMultiplicity multiplicity, Boolean containsTarget) at System.Web.OData.Builder.EntityTypeConfiguration.AddNavigationProperty(PropertyInfo navigationProperty, EdmMultiplicity multiplicity) at System.Web.OData.Builder.ODataConventionModelBuilder.MapEntityType(EntityTypeConfiguration entity) at System.Web.OData.Builder.ODataConventionModelBuilder.MapType(StructuralTypeConfiguration edmType) at System.Web.OData.Builder.ODataConventionModelBuilder.MapTypes() at System.Web.OData.Builder.ODataConventionModelBuilder.GetEdmModel() at XXXXServiceMySql.WebApiConfig.GenerateEdmModel() in c:\PROJECTS\XXXXServiceMySql\XXXXServiceMySql\App_Start\WebApiConfig.cs:line 89 at XXXXServiceMySql.WebApiConfig.Register(HttpConfiguration config) in c:\PROJECTS\XXXXServiceMySql\XXXXServiceMySql\App_Start\WebApiConfig.cs:line 55 at System.Web.Http.GlobalConfiguration.Configure(Action
1 configurationCallback) at XXXXServiceMySql.WebApiApplication.Application_Start() in c:\PROJECTS\XXXXServiceMySql\XXXXServiceMySql\Global.asax.cs:line 17

8/7/2014 4:56:19 PM

Popular Answer

I believe that, as of the latest version WebApi OData v4 (5.4.0), DateTime is supported to a degree. It still is defined as DateTimeOffset in the metadata, but at least your model can deal with DateTime. See for more details.

2/8/2015 4:37:51 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow