【发布时间】:2015-01-12 21:41:08
【问题描述】:
我有一个托管在 CentOS 7 上的 MySQL 服务器,在 Azure 中作为 VM 运行。我已经在这个虚拟机上打开了 3306 端口,我可以连接到这个 MySQL 服务器,从 MySQL 工作台创建一个数据库和表
现在我正在尝试使用 nuget 上的 MySQL.Data.Entity 包在此 MySQL 服务器上使用 EF6 和 C# 创建代码优先数据库。我得到的 MySQL.Data dll 的版本是 6.9.5.0。当我尝试运行 add-migration 命令时,出现以下错误。
System.Runtime.Serialization.SerializationException: Type is not resolved for member 'MySql.Data.MySqlClient.MySqlException,MySql.Data, Version=6.9.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d'.
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
at System.Data.Entity.Migrations.Design.ToolingFacade.Scaffold(String migrationName, String language, String rootNamespace, Boolean ignoreChanges)
at System.Data.Entity.Migrations.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges)
at System.Data.Entity.Migrations.AddMigrationCommand.<>c__DisplayClass2.<.ctor>b__0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Type is not resolved for member 'MySql.Data.MySqlClient.MySqlException,MySql.Data, Version=6.9.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d'.
但是,当我尝试连接到共享 Web 托管服务提供商上的 MySQL 服务器时,这可以正常工作,我被告知在 Windows 服务器上运行。
这是一个已知问题,我们是否无法使用 EF 连接到托管在 Linux 上的 MySQL 数据库。我将不胜感激任何指针
更新 1
我错过了一点,即 MySQL 连接器不是 .NET 框架的一部分,因此没有安装在 GAC 中,如下文所述
http://forums.mysql.com/read.php?38,593463,599082#msg-599082
显然,包管理器会在 GAC 中查找已知类型,但它似乎无法找到 MySql.Data。当 MySQL.Data.dll 被添加到 GAC (\Windows\Microsoft.NET\Framework\v4.0.30319) 但在更新数据库上重新出现时,错误消失了。
更新 2
尝试使用带有 MySqlCommand 的 c# 代码创建数据库,它似乎在同一个项目中完美运行。因此,它似乎不适用于包管理器中的代码优先命令,并且问题似乎与 Azure 上的 MySQL 无关。
【问题讨论】:
标签: mysql azure ef-code-first centos