A B*_*elp 9 mysql dotconnect odata asp.net-web-api entity-framework-6
我们正在创建WebApi 2.2服务,并且正在使用上面列出的技术.我们的后端数据存储区是MySql 5.6.我们使用dotConnect for MySql来处理数据存储.在数据库中,有一个RowVersion列,其类型为Timestamp.在EF中,我成功生成了模型,但我注意到RowVersion设置为DateTime.当我运行WebApi时,我得到以下运行时异常,因此我需要将类型更改为DateTimeOffset,因为Timestamp不可用.
在我们的应用程序中,我们将使用带有ETag的RowVersion进行并发处理.因此,我们只会在我们的应用程序中阅读RowVersion; 每当插入或更新发生时,数据库将自动更新RowVersion.
我不知道如何纠正这个问题...也许,有一些方法可以添加一个自动类型转换,因此模型中的RowVersion是一个Int64,我们通过发送Timestamp.value自动在Int64和Timestamp之间进行转换应用.我们只是阅读它,所以这似乎是合理的.
当我在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 =类型'System.Nullable 1 configurationCallback)位于c:\ PROJECTS\XXXXServiceMySql\XXXXServiceMySql\Global.asax.cs中的XXXXServiceMySql.WebApiApplication.Application_Start():第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
我相信,从最新版本 WebApi OData v4 (5.4.0) 开始,DateTime 在一定程度上得到了支持。它仍然在元数据中定义为 DateTimeOffset,但至少您的模型可以处理 DateTime。有关更多详细信息,请参阅http://odata.github.io/WebApi/datetime-support/ 。
| 归档时间: |
|
| 查看次数: |
1606 次 |
| 最近记录: |