我正在尝试将实体框架 6 与 MySQL 结合使用.
I'm trying to use entity framework 6 with MySQL.
我确实为 Visual Studio 1.1.1 和 MySQL .Net 连接器 6.8.3 安装了 MySQL 插件.
I did install MySQL plugin for visual studio 1.1.1 and MySQL .Net connector 6.8.3.
问题是当我尝试创建新的 ADO.NET 实体模型时,我无法选择 MySQL 作为连接.
The problem is when I try to create a new ADO.NET Entity model, I can't choose MySQL for the connection.
但是如果我从visual studio中的连接工具创建一个连接,我可以看到MySQL
But if I create a connection from the connection tool in visual studio, I can see MySQL
表示当前安装的版本与entity framework 6不兼容,安装最新的connector和插件后怎么可能.还有什么可做的吗?
It means that the version currently installed is not compatible with entity framework 6. How is it possible after that I installed the latest connector and the plugin. Is there anything else to do?
谢谢
编辑
我在没有安装默认连接器的情况下全新安装了 MySQL,然后我安装了 6.8.3 和 Visual Studio 插件.
I did a fresh install of MySQL without installing the default connector and then I installed the 6.8.3 and the plugin for visual studio.
然后我可以看到我为我的实体模型建立的连接,但是当我要选择实体版本时,我收到了这条消息.
Then I can see the connection I made for my Entity model but when I'm about to choose the entity version, I get this message.
LATEST EDIT
错误已修复.
克里斯的评论:
2015-11-07,您现在无需编辑任何文件或做奇怪的事情.使用 MySQL for Windows 安装程序和包括 Visual Studio 支持和最新的 Connector.Net.是安装后一定要更新,你会得到最新的(1.2.5 和 6.9.8).使用 NuGet 安装 EntityFramework、MySql.Data、和 MySql.Data.Entity.最后,构建并享受代码优先反向通过添加 Ado.Net 实体模型来提高工程质量.
2015-11-07 and you can now get it all working without editing any files or doing weird stuff. Use the MySQL for Windows installer and include the Visual Studio support and the latest Connector.Net. Be sure to update after installing and you will get the latest of each (1.2.5 and 6.9.8). Use NuGet to install EntityFramework, MySql.Data, and MySql.Data.Entity. Finally, built and enjoy code-first reverse engineering goodness by adding an Ado.Net Entity Model.
原答案
我发现这是 MySQL 的一个错误.
I found out it's a bug from MySQL.
这里是解释变通方法的链接.
在安装了 VS 2013 的机器上,VS 插件 (1.1.3 GA) 和连接器/网络
On your machine where VS 2013 is installed, VS plugin (1.1.3 GA) and Connector/Net
在执行这些步骤之前关闭所有 VS 实例.
Close all VS instances before doing the steps.
在 Windows 资源管理器窗口中,转到此路径或您安装的任何位置你的连接器/网络二进制文件
On a Windows Explorer window go to this path or wherever you installed you Connector/net binaries
C:\Program Files (x86)\MySQL\MySQL 连接器网络6.8.3\Assemblies\v4.5\
C:\Program Files (x86)\MySQL\MySQL Connector Net 6.8.3\Assemblies\v4.5\
复制文件:
MySql.Data.Entity.EF6.dll
MySql.Data.Entity.EF6.dll
然后粘贴到这个文件夹
C:\Program Files (x86)\Microsoft Visual Studio12.0\Common7\IDE\PrivateAssemblies
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies
如果它要求您覆盖它,请这样做.
If it asks you to overwrite it please do so.
您需要管理员权限才能覆盖文件.
You'll need admin rights in order to overwrite the file.
然后您可以再次尝试为您的模型生成脚本.
Then you can try again to generate the script for your model.
重要的是你有 1.1.3 版本的 VS 插件已安装,因为此解决方法适用于此.
It is important that you have the 1.1.3 version of the VS plugin installed since this workaround is for that.
不幸的是它对我不起作用,所以我降级到实体框架 5,直到他们解决这个问题.
Unfortunately it doesn't work for me, so I downgraded to entity framework 5 until they fix this.
编辑
终于,它现在可以工作了.
Finaly, it works now.
我必须添加以下 3 个 DLL:
I had to add the 3 following DLLs :
然后我将 web 配置中的 EntityFramework 部分更改为:
Then I changed the EntityFramework part in the web config to :
<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
</providers>
</entityFramework>
不要忘记REBUILD,您应该能够使用 MySQL 创建实体框架 6 模型.
Don't forget to REBUILD and you should be able to create a entity framework 6 model with MySQL.
重要
确保您已为 Visual Studio 1.1.3 和 MySQL 连接器 .net 6.8.3 安装了 MySQL
Make sure you have installed MySQL for visual studio 1.1.3 and MySQL connector .net 6.8.3
这篇关于实体框架 6 不能使用 MySQL 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!