【发布时间】:2014-09-30 23:55:21
【问题描述】:
我们正在创建 WebApi 2.2 服务并使用上面列出的技术。我们的后端数据存储是 MySql 5.6。我们正在使用 dotConnect for MySql 来处理数据存储。在数据库中,有一个类型为 Timestamp 的 RowVersion 列。在 EF 中,我成功生成了模型,但我注意到 RowVersion 设置为 DateTime。当我运行 WebApi 时,出现以下运行时异常,因此我需要将类型更改为 DateTimeOffset,因为 Timestamp 不可用。
在我们的应用程序中,我们将使用带有 ETag 的 RowVersion 进行并发处理。因此,我们只会在应用程序中读取 RowVersion;每当插入或更新发生时,数据库将自动更新 RowVersion。
我不知道如何纠正这个问题...也许,有一些方法可以添加自动类型转换,因此模型中的 RowVersion 是 Int64,我们通过发送 Timestamp 自动在 Int64 和 Timestamp 之间转换。对我们的应用程序的价值。我们只是在阅读它,所以这似乎是合理的。
当我在 EF 模型中将 RowVersion 更改为 Int64 并构建应用程序时,我收到以下错误:
错误 1 错误 2019:指定的成员映射无效。方式 成员“版本”的“Edm.Int64[Nullable=True,DefaultValue=]”类型 'Model.customer' 不兼容 'Devart.Data.MySql.timestamp[Nullable=True,DefaultValue=,Precision=0]' 类型中的成员“版本” '模型.商店.客户'。 C:\PROJECTS\ServiceMySql\ServiceMySql\Models\Model.edmx 898 17 ServiceMySql
非常感谢您帮助找出解决此问题的方法。
感谢您的宝贵时间和建议,
迈克
本文开头提到的异常:
System.ArgumentException 未被用户代码处理
HResult=-2147024809 Message=类型 'System.Nullable1[[System.DateTime, mscorlib, Version=4.0.0.0, 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.OData1 配置回调) 在 XXXXServiceMySql.WebApiApplication.Application_Start() 在 c:\PROJECTS\XXXXServiceMySql\XXXXServiceMySql\Global.asax.cs:line 17
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
内部异常:
【问题讨论】:
-
目前web api odata 不支持DateTime,也许会有修复。有一个类似的问题可以解决,希望这会有所帮助stackoverflow.com/questions/24829422/…>
-
某些喜剧演员似乎更改了 OData v4 服务,以破解 99% 的已编写并处理日期时间信息的所有代码,选择:aspnetwebstack.codeplex.com/workitem/1753。
-
另一个类似的线程 stackoverflow.com/questions/25189557/… 。希望这可以暂时帮助您解决问题
标签: mysql asp.net-web-api odata entity-framework-6 dotconnect