Mysql data entity not found

LATEST EDIT

The bug has been fixed.

Chris' comment:

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.

Original answer

I found out it's a bug from MySQL.

Here's the link explaining a workarround.

On your machine where VS 2013 is installed, VS plugin (1.1.3 GA) and Connector/Net

Close all VS instances before doing the steps.

On a Windows Explorer window go to this path or wherever you installed you Connector/net binaries

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

Copy the file:

MySql.Data.Entity.EF6.dll

And paste it to this folder

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.

It is important that you have the 1.1.3 version of the VS plugin installed since this workaround is for that.

Unfortunately it doesn't work for me, so I downgraded to entity framework 5 until they fix this.

EDIT

Finaly, it works now.

I had to add the 3 following DLLs :

  • C:\Program Files (x86)\MySQL\MySQL Connector Net 6.8.3\Assemblies\v4.5\MySql.Data.dll
  • C:\Program Files (x86)\MySQL\MySQL Connector Net 6.8.3\Assemblies\v4.5\MySql.Data.Entity.EF6.dll
  • C:\Program Files (x86)\MySQL\MySQL Connector Net 6.8.3\Assemblies\v4.5\MySql.Web.dll

Then I changed the EntityFramework part in the web config to :


    
    
       
    
  

Don't forget to REBUILD and you should be able to create a entity framework 6 model with MySQL.

IMPORTANT

Make sure you have installed MySQL for visual studio 1.1.3 and MySQL connector .net 6.8.3

MySQL Connector/NET integrates support for Entity Framework 6 (EF6), which now includes support for cross-platform application deployment with the EF 6.4 version. This chapter describes how to configure and use the EF6 features that are implemented in Connector/NET.

In this section:

  • Minimum Requirements for EF6 on Windows Only

  • Minimum Requirements for EF 6.4 with Cross-Platform Support

  • Configuration

  • EF6 Features

  • Code First Features

  • Example for Using EF6

Minimum Requirements for EF6 on Windows Only

  • Connector/NET 6.10 or 8.0.11

  • MySQL Server 5.6

  • Entity Framework 6 assemblies

  • .NET Framework 4.5.1 (.NET Framework 4.5.2 for Connector/NET 8.0.22)

Minimum Requirements for EF 6.4 with Cross-Platform Support

  • Connector/NET 8.0.22

  • MySQL Server 5.6

  • Entity Framework 6.4 assemblies

  • .NET Standard 2.1 (.NET Core SDK 3.1 and Visual Studio 2019 version 16.5)

Configuration

Note

The MySQL Connector/NET 8.0 release series has a naming scheme for EF6 assemblies and NuGet packages that differs from the scheme used with previous release series, such as 6.9 and 6.10. To configure Connector/NET 6.9 or 6.10 for use with EF6, substitute the assembly and package names in this section with the following:

  • Assembly: MySql.Data.Entity.EF6

  • NuGet package: MySql.Data.Entity

    For more information about the MySql.Data.Entity NuGet package and its uses, see https://www.nuget.org/packages/MySql.Data.Entity/.

To configure Connector/NET support for EF6:

  1. Edit the configuration sections in the app.config file to add the connection string and the Connector/NET provider.

    
        
    
    
        
        
            
            
        
    
  2. Apply the assembly reference using one of the following techniques:

    • NuGet package.  Install the NuGet package to add this reference automatically to the app.config or web.config file during the installation. For example, to install the package for Connector/NET 8.0.22, use one of the following installation options:

      • Command Line Interface (CLI)

        dotnet add package MySql.Data.EntityFramework -Version 8.0.22
      • Package Manager Console (PMC)

        Install-Package MySql.Data.EntityFramework -Version 8.0.22
      • Visual Studio with NuGet Package Manager. For this option, select nuget.org as the package source, search for mysql.data, and install a stable version of MySql.Data.EntityFramework.

    • MySQL Installer or the MySQL Connector/NET MSI file.  Install MySQL Connector/NET and then add a reference for the MySql.Data.EntityFramework assembly to your project. Depending on the .NET Framework version used, the assembly is taken from the v4.0, v4.5, or v4.8 folder.

    • MySQL Connector/NET source code.  Build Connector/NET from source and then insert the following data provider information into the app.config or web.config file:

      
         
           
           
         
      

      Important

      Always update the version number to match the one in the MySql.Data.dll assembly.

  3. Set the new DbConfiguration class for MySQL. This step is optional but highly recommended, because it adds all the dependency resolvers for MySQL classes. This can be done in three ways:

    • Adding the DbConfigurationTypeAttribute on the context class:

      [DbConfigurationType(typeof(MySqlEFConfiguration))]
    • Calling DbConfiguration.SetConfiguration(new MySqlEFConfiguration()) at the application start up.

    • Set the DbConfiguration type in the configuration file:

    It is also possible to create a custom DbConfiguration class and add the dependency resolvers needed.

EF6 Features

Following are the new features in Entity Framework 6 implemented in Connector/NET:

  • Cross-platform support in Connector/NET 8.0.22 implements EF 6.4 as the initial provider version to include Linux and macOS compatibility with .NET Standard 2.1 from Microsoft.

  • Async Query and Save adds support for the task-based asynchronous patterns that have been available since .NET 4.5. The new asynchronous methods supported by Connector/NET are:

    • ExecuteNonQueryAsync

    • ExecuteScalarAsync

    • PrepareAsync

  • Connection Resiliency / Retry Logic enables automatic recovery from transient connection failures. To use this feature, add to the OnCreateModel method:

    SetExecutionStrategy(MySqlProviderInvariantName.ProviderName, () => new MySqlExecutionStrategy());
  • Code-Based Configuration gives you the option of performing configuration in code, instead of performing it in a configuration file, as it has been done traditionally.

  • Dependency Resolution introduces support for the Service Locator. Some pieces of functionality that can be replaced with custom implementations have been factored out. To add a dependency resolver, use:

    AddDependencyResolver(new MySqlDependencyResolver());

    The following resolvers can be added:

    • DbProviderFactory -> MySqlClientFactory

    • IDbConnectionFactory -> MySqlConnectionFactory

    • MigrationSqlGenerator -> MySqlMigrationSqlGenerator

    • DbProviderServices -> MySqlProviderServices

    • IProviderInvariantName -> MySqlProviderInvariantName

    • IDbProviderFactoryResolver -> MySqlProviderFactoryResolver

    • IManifestTokenResolver -> MySqlManifestTokenResolver

    • IDbModelCacheKey -> MySqlModelCacheKeyFactory

    • IDbExecutionStrategy -> MySqlExecutionStrategy

  • Interception/SQL logging provides low-level building blocks for interception of Entity Framework operations with simple SQL logging built on top:

    myContext.Database.Log = delegate(string message) { Console.Write(message); };
  • DbContext can now be created with a DbConnection that is already opened, which enables scenarios where it would be helpful if the connection could be open when creating the context (such as sharing a connection between components when you cannot guarantee the state of the connection)

      [DbConfigurationType(typeof(MySqlEFConfiguration))]
      class JourneyContext : DbContext
      {
        public DbSet MyPlaces { get; set; }
    
        public JourneyContext()
          : base()
        {
    
        }
    
        public JourneyContext(DbConnection existingConnection, bool contextOwnsConnection)
          : base(existingConnection, contextOwnsConnection)
        {
    
        }
      }
    
      using (MySqlConnection conn = new MySqlConnection(""))
      {
        conn.Open();
        ...
    
        using (var context = new JourneyContext(conn, false))
        {
          ...
        }
      }
  • Improved Transaction Support provides support for a transaction external to the framework as well as improved ways of creating a transaction within the Entity Framework. Starting with Entity Framework 6, Database.ExecuteSqlCommand() will wrap by default the command in a transaction if one was not already present. There are overloads of this method that allow users to override this behavior if wished. Execution of stored procedures included in the model through APIs such as ObjectContext.ExecuteFunction() does the same. It is also possible to pass an existing transaction to the context.

  • DbSet.AddRange/RemoveRange provides an optimized way to add or remove multiple entities from a set.

Code First Features

Following are new Code First features supported by Connector/NET:

  • Code First Mapping to Insert/Update/Delete Stored Procedures supported:

    modelBuilder.Entity().MapToStoredProcedures();
  • Idempotent migrations scripts allow you to generate an SQL script that can upgrade a database at any version up to the latest version. To do so, run the Update-Database -Script -SourceMigration: $InitialDatabase command in Package Manager Console.

  • Configurable Migrations History Table allows you to customize the definition of the migrations history table.

Example for Using EF6

The following C# code example represents the structure of an Entity Framework 6 model.

using MySql.Data.Entity;
using System.Data.Common;
using System.Data.Entity;

namespace EF6
{
  // Code-Based Configuration and Dependency resolution
  [DbConfigurationType(typeof(MySqlEFConfiguration))]
  public class Parking : DbContext
  {
    public DbSet Cars { get; set; }

    public Parking()
      : base()
    {

    }

    // Constructor to use on a DbConnection that is already opened
    public Parking(DbConnection existingConnection, bool contextOwnsConnection)
      : base(existingConnection, contextOwnsConnection)
    {

    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
      base.OnModelCreating(modelBuilder);
      modelBuilder.Entity().MapToStoredProcedures();
    }
  }

  public class Car
  {
    public int CarId { get; set; }

    public string Model { get; set; }

    public int Year { get; set; }

    public string Manufacturer { get; set; }
  }
}

The C# code example that follows shows how to use the entities from the previous model in an application that stores the data within a MySQL table.

using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;

namespace EF6
{
  class Example
  {
    public static void ExecuteExample()
    {
      string connectionString = "server=localhost;port=3305;database=parking;uid=root";

      using (MySqlConnection connection = new MySqlConnection(connectionString))
      {
        // Create database if not exists
        using (Parking contextDB = new Parking(connection, false))
        {
          contextDB.Database.CreateIfNotExists();
        }

        connection.Open();
        MySqlTransaction transaction = connection.BeginTransaction();

        try
        {
          // DbConnection that is already opened
          using (Parking context = new Parking(connection, false))
          {

            // Interception/SQL logging
            context.Database.Log = (string message) => { Console.WriteLine(message); };

            // Passing an existing transaction to the context
            context.Database.UseTransaction(transaction);

            // DbSet.AddRange
            List cars = new List();

            cars.Add(new Car { Manufacturer = "Nissan", Model = "370Z", Year = 2012 });
            cars.Add(new Car { Manufacturer = "Ford", Model = "Mustang", Year = 2013 });
            cars.Add(new Car { Manufacturer = "Chevrolet", Model = "Camaro", Year = 2012 });
            cars.Add(new Car { Manufacturer = "Dodge", Model = "Charger", Year = 2013 });

            context.Cars.AddRange(cars);

            context.SaveChanges();
          }

          transaction.Commit();
        }
        catch
        {
          transaction.Rollback();
          throw;
        }
      }
    }
  }
}


Does Visual Studio 2022 support MySQL?

MySQL isn't supported for Visual Studio 2022 yet. it's weird and frustrating, to be honest, but if you want to work with MySQL with VS22, you either need to change the Database or go back to VS19.

Can Entity Framework work with MySQL?

MySQL Connector/NET integrates support for Entity Framework 6 (EF6), which now includes support for cross-platform application deployment with the EF 6.4 version.

How to add MySQL Entity Framework in Visual Studio 2019?

Let's get started..
Step 1 - Create .NET Core 3.1 project on Visual Studio 2019..
Step 2 - Install dependency packages..
Step 3 - Install MySQL Workbench and MySQL Server..
Step 4 - Create model classes..
UserGroup.cs..
User.cs..
Step 5 - Create a database context..
Step 6: Configure and inject the database connection..