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 15:57

I know the solution.

Nuget installs edge version of MySql.Data.* packages, while you probably have previous version of the connector (In my case packages were v. 6.9.6 and Connector was 6.9.5). This comes to the point where you have version mismatch.

Be aware that if you use Install-Package MySql.Data.Entities in NuGet you will get even older version like 6.8.3, so you have to add the references by yourself and keep an eye on which one you are trying to add to your solution.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-01-06 15:59

I just had the same situation when trying to configure Visual Studio Professional 2017 environment with MySQL, ADO.NET (Database First) and EF6.

Note: Please follow steps in the same order.

  1. Uninstall/remove "Connector/NET" and "MySQL for Visual Studio" if installed.

  2. Install "MySQL for Visual Studio" v2.0.5 CTP (MySQL for Visual Studio). Note: Install MySQL for Visual Studio before Connector/NET.

  3. Install "Connector/NET" v6.9.10 (Connector/Net). https://i.stack.imgur.com/XOT1I.jpg Note: I tried using Connector/NET v6.8, v6.10 and v8 first, but none of them worked with Visual Studio 2017 and ADO.Net. Here you can find all Connector Versions and Compatibilities with Visual Studio IDEs, but so far this list is inaccurate.

  4. Create new Visual Studio Professional 2017 project.

  5. Download and Install "EntityFramework" v6.2.0 through NuGet, by going to Project Tab/Manage NuGet Packages/Browse -> Entity Framework.

  6. Add references to C:\Program Files (x86)\MySQL\Connector.NET 6.9.10\Assemblies\v4.5\MySql.Data.dll and C:\Program Files (x86)\MySQL\Connector.NET 6.9.10\Assemblies\v4.5\MySql.Data.Entity.EF6.dll; by Right Clicking over References inside Solution Explorer and selecting Add Reference/Browse ->Browse button.

  7. Add MySQL EF6 provider info inside App.config under entity framework providers as follow:

<entityFramework>
       <providers>
         <provider invariantName="MySql.Data.MySqlClient"
              type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
       </providers>
</entityFramework>

  1. Rebuild project by going to Build tab/Rebuild ProjectName.

And that's it. VS2017 is ready to go. Hope this works for everybody, as it did for me today.

References:

  1. Can't Create Entity Data Model - using MySql and EF6

  2. No Entity Framework provider found for 'MySql.Data.MySqlClient' ADO.NET provider

查看更多
ゆ 、 Hurt°
4楼-- · 2019-01-06 15:59

I had the same problem using MySQL Connector 6.9.8.0. While all my versions matched, this still failed. I had installed a new version of Visual Studio AFTER the MySQL connector (From 2010 to 2013). For me, the solution was to uninstall the MySQL Connector for NET and then reinstall it (Exact same version). Then restart Visual Studio.

Seems like this is another version of the same problem.

查看更多
冷血范
5楼-- · 2019-01-06 16:02

You can do this solution:

  1. Add a new empty EF model.
  2. In the emdx design rigth click and update the model from database.
  3. choose your database and the model will be generate.

That's work for me :)

查看更多
萌系小妹纸
6楼-- · 2019-01-06 16:10

I changed my web.config file from:

<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.EntityFramework, Version=8.0.11.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />

To:

<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"></provider>

查看更多
爱情/是我丢掉的垃圾
7楼-- · 2019-01-06 16:12

Taking suggestions about NuGet versioning from others answers. I solved this issue by deleting the .Data and Data.Entitiy.EF6 installed by Nuget.

Then right click on References and browse for:

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

I was then able to complete the ADO.Net wizard, with the .edmx models.

查看更多
登录 后发表回答