您的位置:首页 > 数据库 > MySQL

EntityFrameworkCode 操作MySql 相关问题

2018-09-25 23:56 585 查看

近段时间,由于工作原因,使用到了EntityFrameworkCore 操作MySql数据库,使用中遇到一些问题,特此记录

系统环境 Win10 1805,VS 2017,Framework:Asp.NetCore 2.0

1. InvalidCastException: Unable to cast object of type 'ConcreteTypeMapping' to type 'Microsoft.EntityFrameworkCore.Storage.RelationalTypeMapping'.

项目依赖相关信息

Asp.NetCore2.0 , EntityFrameworkCore 2.1.0~2.1.3 稳定版 , MySql.Data.EntityFrameworkCore 6.10.7~8.0.12 稳定版

错误详细

如何解决

通过阅读 MySql.Data.EntityFrameworkCore 官方文档 得出结论 可能是MySql.Data.EntityFrameworkCore 与 EntityFramework Core 版本不兼容所致。

更换 MySql.Data.EntityFrameworkCore或者EntityFramework Core与之相兼容的版本即可。

这里我切换的版本为

Asp.Net Core 2.0 & EntityFrameworkCore 2.0.3 & MySql.Data.EntityFrameworkCore 8.0.12

具体版本对应参照如下 (官方地址)

MySql.Data.EntityFrameworkCore Supported versions of Entity Framework Core
Connector/NET EF Core 1.1 EF Core 2.0 EF Core 2.1
6.10.4 .NET Standard 1.3 or .NET Framework 4.5.2 (and later) Not supported Not supported
6.10.5 to 6.10.7 .NET Standard 1.3 or .NET Framework 4.5.2 (and later) .NET Standard 2.0 only (.NET Framework is not supported)
Scaffolding is not supported
Not supported
6.10.8 .NET Standard 1.3 or .NET Framework 4.5.2 .NET Standard 2.0 or .NET Framework 4.6.1 (and later) Not supported
8.0.11 to 8.0.12 .NET Standard 1.6 or .NET Framework 4.5.2 (and later) .NET Standard 2.0 only (.NET Framework is not supported)
Scaffolding is not supported
Not supported
参考文章

MySQL Connector/NET Developer Guide

MySql(Entity Framework Core Support)

数据库提供程序(Microsoft Docs)

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: