Can't Create Entity Data Model - using MySql a

2019-01-06 15:57发布

I'm trying to add an edmx Entity model to my C#/Web Project in Visual Studio 2013. My problem is that the file is not created.

I do the following steps:

  1. Give the item a name
  2. Choose 'EF Designer from database'
  3. Choose the connection from the drop down (localhost) that already tested successfully connecting to MySQL databse
  4. The "Save connection settings in webc.config as" option is checked
  5. I click 'Next' AND the window disappeared and I get back to the code window

No edmx file is created. (although it works with SQL Server, but not for MySQL)

I have Entity Framework 6.1.2 installed, MySql.Data, MySql.Data.Entities, MySql.Data.Entity, MySql.Web -- all installed.

I also rebuilt the project before trying to add an entity model file.

I've installed the latest MySQL package with the latest .NET connector.

Running: Visual Studio 2013 on Windows 7.

Any ideas how to solve this?

11条回答
一夜七次
2楼-- · 2019-01-06 16:14

This is for an ASP.NET MVC application, which does not have an app.config file. I will not recount the failed attempts, but what worked for me was the following:-

  • With VS not running, download and install "MySQL for Visual Studio 2.0.5" - the latest version at time of writing.
  • Start VS2017 and uninstall the "MySql.Data.Entity" and "MySql.Data" NuGet packages, if they have been previously installed in VS2017.
  • Download and install the latest MySql connector/NET using the links above (version 8.0.13 at time of writing).
  • In your project add references to the "MySql.Data.dll" and "MySql.Data.EntityFramework.dll" dlls as described above by Lopez93, but N.B. the "MySql.Data.Entity.EF6.dll" mentioned did not exist in 8.0.13, only "MySql.Data.EntityFramework.dll".
  • Now edit the web.config file and make sure that in the section, there is this line

<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.EntityFramework">

  • Remove or comment out any other '<provider invariantName="MySql.Data.MySqlClient"...' lines.

  • Rebuild the project.

Try using the wizard again.

For me this worked.

Good luck!

查看更多
别忘想泡老子
3楼-- · 2019-01-06 16:16

VS 2015 still has this bug. It is caused by version mismatch.

On my system, I had MySQL Connector 6.9.6.
Issuing the command in NuGet Package Manger Console:

Install-Package MySql.Data.Entity

installs version 6.9.8 by default. Your connector must match the actual version of the NuGet Package.
You can download an updated version of the connector from: https://www.mysql.com/products/connector/

Here select the "Ado.net driver for MySQL", and download the corresponding version (in this case 6.9.8). Reopen Visual Studio and now the wizard does not crash. No reboot required.

查看更多
够拽才男人
4楼-- · 2019-01-06 16:20

I was able to resolve this problem by performing the following:

  1. Open MySQL Installer and install the latest version of Connector/NET
  2. Uninstall / reinstall the latest version MySQL.Data.* packages with versions that match the version of the newly installed Connector/NET package
  3. Restart Visual Studios
  4. Rebuild solution
查看更多
成全新的幸福
5楼-- · 2019-01-06 16:23

I solved this issue by following some steps below:

  1. Uninstall MySql.Data.Entities from Nuget by using command below in Package Manager Console: Uninstall-Package MySql.Data.Entities

  2. Add project reference to the latest MySql.Data.Entity.EF6.dll from your MySql connector installation path at: C:\Program Files (x86)\MySQL\MySQL Connector Net 6.9.8\Assemblies\v4.5

查看更多
混吃等死
6楼-- · 2019-01-06 16:24

another thing to try:

--->install the entityframework 6.2.0 via nuget.

--->Verify in your web.config/app.config file that you have the System.Data.SqlServerCe.4.0 provider. if it's not installed, then install it via nuget, the exact same version as the entity framework previously installed (6.2.0 in this case).

--->then add the references: (in this case from the connector/NET version 6.9.10) C:\Program Files (x86)\MySQL\Connector.NET 6.9\Assemblies\v4.5\MySql.Data.dll and C:\Program Files (x86)\MySQL\Connector.NET 6.9\Assemblies\v4.5\MySql.Data.Entity.EF6.dll and rebuild.

--->try adding this provider too: <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" /> rebuild, again.

--->and finally, try adding the .edmx file with a new connection.

This worked in my case where i installed VS2017 and MySQL in a brand new laptop, and had the same issue.

查看更多
登录 后发表回答