我们正在创建 WebApi 2.2 服务并使用上面列出的技术。我们的后端数据存储是 MySql 5.6。我们正在使用 dotConnect for MySql 来处理数据存储。在数据库中,有一个类型为 Timestamp 的 RowVersion 列。在 EF 中,我成功生成了模型,但我注意到 RowVersion 设置为 DateTime。当我运行 WebApi 时,出现以下运行时异常,因此我需要将类型更改为 DateTimeOffset,因为 Timestamp 不可用。
在我们的应用程序中,我们将使用带有 ETag 的 RowVersion 进行并发处理。因此,我们只会在应用程序中读取 RowVersion;每当插入或更新发生时,数据库将自动更新 RowVersion。
我不知道如何纠正这个问题......也许,有一些方法可以添加自动类型转换,因此模型中的 RowVersion 是 Int64,我们通过将 Timestamp.value 发送到我们的应用。我们只是在阅读它,所以这似乎是合理的。
当我在 EF 模型中将 RowVersion 更改为 Int64 并构建应用程序时,我收到以下错误:
错误 1 错误 2019:指定的成员映射无效。'Model.customer' 类型中成员 'Version' 的类型 'Edm.Int64[Nullable=True,DefaultValue=]' 与 'Devart.Data.MySql.timestamp[Nullable=True,DefaultValue=,Precision=0' 不兼容'Model.Store.customers' 类型的成员 'Version' 的 ]'。C:\PROJECTS\ServiceMySql\ServiceMySql\Models\Model.edmx 898 17 ServiceMySql
非常感谢您帮助找出解决此问题的方法。
感谢您的时间和建议,
麦克风
本文开头提到的异常:
System.ArgumentException 未被用户代码
HResult=-2147024809 Message=The type 'System.Nullable 1 configurationCallback) at XXXXServiceMySql.WebApiApplication.Application_Start() in c:\PROJECTS\XXXXServiceMySql\XXXXServiceMySql\Global.asax.cs:line 17 InnerException :1[[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.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