Question

Yesterday I knew that Entity Framework is another method to access database beside using Dataset or DataReader,then I tried to make Entity Framework 6 work for my MySql database server in MVS 2013.

I open a WinForms with .Net FrameWork 4.5.1. (so I only have App.config but no app/web config in the project) After I installed mysql-installer-community-5.7.3.0-m13.msi and

install EntityFramework package via

TOOLS menu -> Library Package Manager -> Manage NuGet Packages for Solution... -> Online -> (Search) EntityFramework (beware of version of this package and it should be version 6.0.2, if not then click Updates -> EntityFramework to update)

When I tried to add ADO.NET Entity Data Model via

Right click Project -> Add -> New Item -> ADO.NET Entity Data Model -> Generate from Database -> New Connection -> Data sources: -> Change...-> MySQL Database -> Fill in the Server name with server IP, Username and Password -> Choose the Database name-> Test Connection -> OK

Then Entity Connection string is generated -> Tick Save entity connection settings in App.Config as -> Next> ->

Which version of Entity Framework do you want to use? Have option Entity Framework 6.0 but you cannot use it because

"Your project references the latest version of Entity Framework; however, an Entity Framework database provider compatible with this version could not be found for your data connection. Exit this wizard, install a compatible provider, and rebuid your project before performing this action".

How to solve this?

By the way , if you install Entity Framework version 5 in Nuget Package then you might have option Entity Framework 5.0 here and you might success to use Entity Framework 5 but not the version 6.

Était-ce utile?

La solution

First of all, we don't even need to install the mysql-installer-community-5.7.3.0-m13.msi.

  1. Install the latest mysql-visualstudio-plugin
  2. Install the latest mysql-connector-net
  3. New C# .Net 4.5 Framework WinForms (for 4.0 it should work based on Does Entity Framework 6 support .NET 4.0? )
  4. Install 4 Nuget Packages (follow sequence, if you install Mysql.Data.Entities before EntityFramework, it will resolve dependency and install EntityFramework 6.0.2 but what we need is EntityFramework 6.1.0)

EntityFramework

Mysql.Data

Mysql.Data.Entities

Mysql.Web

5.If you have tag entityFramework in App.config, please comment it and insert new tag entityFramework in App.config after tag startup

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

6.Add ADO.NET Entity Data Model (as mentioned in question)

7.After Entity Connection string is generated (as mentioned in question) and Tick Save entity connection settings in App.Config as then click Next

8.Choose Your Database Object and Settings (Tables, Views, or Stored Procedures and Functions) (Don't have "Which version of Entity Framework do you want to use?" because I have only one Entity Framework 6.0 provider so direct skip the selection if my only provider is valid)

9.Finish

Congratulations ^^

By the way, you may need to add the .dll files

  • MySql.Data.dll
  • MySql.Data.Entity.EF6.dll
  • MySql.Web.dll

inside this folder

C:\Program Files\MySQL\MySQL Connector Net 6.8.3\Assemblies\v4.5 (32bit windows)

C:\Program Files (x86)\MySQL\MySQL Connector Net 6.8.3\Assemblies\v4.5 (64bit windows)

as your project reference for further EF6 functions.

Autres conseils

I followed the instructions given by V-Shy and was having the same problem as LaRae White with the wizard shutting down on me. I'm running VS2015 and had just used the MySql installer to update to MySQL for Visual Studio v1.2.6 and Connector/NET v6.9.8.

What I eventually did to get it to work was this:

  1. Uninstall all the packages I had previously installed to solve this issue (EntityFramework, Mysql.Data, Mysql.Data.Entities, Mysql.Web)
  2. Added the following references found in C:\Program Files (x86)\MySQL\Connector.NET 6.9\Assemblies\v4.5 manually: MySql.Data.dll, MySql.Data.Entity.EF6.dll, and MySql.Web.dll

I hope that helps someone out.

I spend entire day figuring out how to solve this problem and nothing helps. Apparently i figure out 1 things about which people don't mention

In the model.edmx properties there is entire "DDL Generation Template", by default it set to "SSDLToSQL10.tt (VS)" but need to be set to "SSDLToMySQL.tt (VS)"

What is more it was also producing an error:

Running transformation: System.NullReferenceException: Object reference not set to an instance of an object.
bla bla bla
line 93 c:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen\SSDLToMySQL.tt

What leads me to the official bug in "MySQL for Visual Studio 1.1.3" which will be fixed in next build 1.1.4 which is not available so far.

However there is workaround fix:
Overwrite the "MySql.Data.Entity.EF6.dll" in
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies
by file from NET Connector in
C:\Program Files (x86)\MySQL\MySQL Connector Net 6.8.3\Assemblies\v4.5\

The fix is as follows:

  1. Install MySQL Visual Studio Plugin
  2. Install MySQL Connector for .NET
  3. Add references in project from MySQLConnector Assemblies inside Program Files.
  4. Remove old code from App.Config or Web.Config

    <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="mssqllocaldb" /> </parameters> </defaultConnectionFactory> <providers> <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> </providers> </entityFramework>

  5. Replace with code given below:

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

  6. Rebuild the project and try adding new ADO .NET Entity Data Model

Ensure that your DbContext has the annotation as shown in the MySQL documentation:

[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public partial class MyDbContext : DbContext
{
}

I kept finding that my database first ASP.NET MVC application would allow me to update my EDMX file up until I got it out of source control on another machine.

I hope that this helps someone who can't update their EDMX or finds the error when using MySQL with Entity Framework 6 as I kept getting faced with the same error until I added the annotation.

I had the same problem, and tried various fixes like the ones here, also some from the MySQL forum and still couldn't update my EDMX.

After some time (awfully long hours), I managed to get this thing working with VS 2013 update 3, .Net connector 6.9.4, Mysql for VS 1.2.3 for my MvcApplication.

First, I tried on a brand new machine, everything worked with a simple install of VS followed by the connector and Mysql for VS. Then, I also tried with an old VS 2012 and it also worked. I had already written some projects with EF5 on my machine and supposed the old EF5 files could be interfering with the EF6 ones.

So here's what I did, but you have to keep in mind that this is a machine-related problem and that I'm giving you a list of all the things I tried in desperation :

  1. Delete all the MySql.*.dll in the C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies folder

  2. Overwrite MySql.Data.Entity.dll in the folder C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PublicAssemblies with the one in the Connector folder

  3. Uninstall EntityFramework from your project in the Nuget console and then downgrade to EF 6.0.0 : Install-Package EntityFramework -ProjectName YourProject -version 6.0.0

  4. Add the reference to MySql.Data.Entity.EF6 not with Nuget but by referencing the file directly (C:\Program Files (x86)\MySQL\MySQL Connector Net 6.9.4\Assemblies\v4.5\MySql.Data.Entity.EF6.dll)

My app.config file looks like this

<configuration>
    <configSections>
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
        <providers>
            <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
            <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        </providers>
    </entityFramework>
    <connectionStrings>
        <!-- your connection string here -->
    </connectionStrings>
</configuration>

And the references added in the project are these three

  • EntityFramework
  • EntityFramework.SqlServer
  • MySql.Data.Entity.EF6

Maybe some of the steps were useless but now I can finally update my EDMX file, and, of course, build and run the Web Project and VS doesn't seem affected by the deletion of the MySql DLLs. Hope it helps.

I had the same issue too. In my case, I had to:

  • Rebuild the project after adding packages prior to starting the add model wizard.
  • Uninstall latest version of entity framework package and revert back to version 6.0.0.0.
  • NOT install Mysql.Data.Entities.EF6 after installing Mysql.Data.Entities!!
  • Change configuration file so that only one MySql.Data.MySqlClient provider is inside providers and that should have included the version:

    <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
    </providers>
    

I have a similar problem with VS2013 Community, but mine isn't WinForm but ASP.NET MVC. After following all of solutions above and my problems still be there, but they (especially Hamed) gave me some ideas to fix it.

So if you still scroll to here, this might give you also an idea. I have:

  1. Installed MySQL Connector NET 6.8.4 (6.9.5 doesn't seem to work).
  2. Leaved MySQL for VS 1.2.3 as is (no need to install 1.1.1 since 1.2.3 worked).
  3. Installed MySQL.data Mysql.Data.entities from NuGet.
  4. Removed all MySQL.dll from D:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies.
  5. Done as Hamed said.
  6. Rebuilt Solution.
  7. Added new ADO.NET Entity Model successfully.

Hope this help.

After struggling for hours during the last 2 days, what finally helped me is to revert all of my code to the old EF5 code, delete the ADO .NET Entity Data Model and re-add it WITHOUT choosing entity framework 6.0 (which was disabled), but choosing 5.0. Due to the lastest mysql connector, visual studio plugin and all the other stuff that I installed as mentioned above, visual studio automatically added a Entity Framework 6.0 ADO entity data model ignoring my "selection". I then added all of the references manually in whatever project asked for it (EntityFramework, mysql.data, mysql.data.entity.EF6 ver 6.9.6) and finally it works.

I had problems like ih303. How I fixed it:

-Follow solution V-SHY

-if there are no error messages or anything like that, the wizard just goes away -> do following solution (which worked for me):

instead of putting in:

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

change it to following:

    <entityFramework>
      <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
        <parameters>
          <parameter value="mssqllocaldb" />
        </parameters>
      </defaultConnectionFactory>
      <providers>
        <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
        <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      </providers>
    </entityFramework>

rebuild -> add wizard and so on -> should work.

I managed to get it working by removing the references for:

MySql.Data.Entity.EF6
MySql.Data

And instead I installed the Nuget

MySql.Data.Entity

What it did is not only add references to the frameworks removed above, but it also made some configuration changes in the project. After I installed the nuget, I also rebuilt the project, so that the dll files would be added to the bin directory.

None of these answers solved it for me. The only thing that worked was to install MySql.Data.EntityFramework NuGet package. I restarted VS, rebuilt and was then able to get through the wizard. (WPF in VS2017 15.8.7).

For me this seems to have something to do with 32-bit VS 64-bit database drivers.

At least at this point I can switch back and forth between having this error and not having this error by changing my configuration to x64. Trying Any CPU does not work, and trying x86 does not work.

I'm not sure where to decide whether to use 32 or 64 bit MySQL drivers; the installer claims to install both.

(I also needed to add one or more of the NuGet packages MySql.Data, MySql.Data.Entity, and MySql.Data.Entities, as well as EntityFramework.)

Once I had the model added to my project I was able to switch the project back to x86 with no problems so far.

When we add item ADO.NET Entity Data Model with Oracle connection then error message displaying "Your project references the latest version of Entity Framework..."

Resolution steps are here ;

  1. Install Oracle ODTwithODAC122010 as a 32Bit

  2. Create Your Project in VS2017

  3. Change Active Solution Platform to 32 Bit from AnyCPU

  4. Open Tools->Nuget PackageManager-> Manage Nuget Packages for Solution

  5. Write Browse Area "ODP" and Install Following Program

Oracle. ManagedDataAccess and Oracle.ManagedDataAccess.EntityFramework

6.Open Tools->Nuget PackageManager-> Package Manager Console

7.Write this Install-Package EntityFramework -Version 6.1.1 and Enter

8.Re-Start Visual Studio to finish the process

9.Re-Build your application

  1. Add new item ADO.NET Entity Data Model

11.If required Add New Connection to Oracle (Data Source = Oracle Database(ODP.NET, Managed Driver))

12.Everything is OK.

Note I quess EF6.1.3 is not working with VS2017 and Oracle ODTwithODAC122010. But after all of these process I have changed EF as a EF6.1.3 it is working But I do not advice you.

The solution that worked for me was first to follow the steps of @V-SHY and install MySql.Data.Entity

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top