0

I'm setting up a solution containing two projects: 1) my class library and 2) my web UI. Ultimately the website will be used to show query results from an existing mysql database.

I struggled to create the ado.net entity model for a while. But I thought I had figured it out after updating the mysql connector for visual studio and following the instructions here: https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html

Now that the entity model is created I am struggling to create a simple controller with scaffolding. I've double checked my connection string and ef provider in web.config and app.config.

I've looked through these questions but have not found my answer:

Exception has been thrown by the target of an invocation- while creating the controller

Application can't scaffold items

Enity Framework With MySQL

I'm pretty sure the issue is in how I have configured it. For a while I thought that what is in app.config didn't matter because the UI project (containing web.config) was set as the startup project. Now I'm just confused. Which is why I have included both below. Any insight is greatly appreciated.

From web.config:

  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-MySolution.UI-20161111094519.mdf;Initial Catalog=aspnet-MySolution.UI-20161111094519;Integrated Security=True"
      providerName="System.Data.SqlClient" />
    <add name="MySolutionEntities" connectionString="metadata=res://*/Entities.DevData.csdl|res://*/Entities.DevData.ssdl|res://*/Entities.DevData.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=****;user id=****;password=****;database=mydatabase&quot;"
      providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
      <provider invariantName="System.Data.MySqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFrameworkSqlServer" />
    </providers>
  </entityFramework>

From app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" 
                type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
    <provider invariantName="MySql.Data.SqlClient" 
              type="MySql.Data.Entity.SqlServer.ProviderServices, EntityFramework.SqlServer"/></providers>
  </entityFramework>
<system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="MySolutionEntities" connectionString="metadata=res://*/Entities.DevData.csdl|res://*/Entities.DevData.ssdl|res://*/Entities.DevData.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=****;user id=****;password=****;database=mydatabase&quot;" 
         providerName="System.Data.MySqlClient" />
  </connectionStrings>
</configuration>
Community
  • 1
  • 1
Jaclyn Noga
  • 1
  • 1
  • 4
  • Show the controller that is exploding? Interested in constructor. I suspect you have a dependency in the constructor, but the framework does not know how to resolve this dependency – trailmax Nov 11 '16 at 17:13
  • Hi @trailmax, I'm getting the exception when attempting to create the create the controller so I can't show you the code – Jaclyn Noga Nov 11 '16 at 17:52

3 Answers3

1

Late answer but I hope it helps somebody I had same problem, I just solve it by uninstalling and reinstalling entity-framework through the nuget package manager console. o Run Package Manager Console :

Tools -> NuGet Package Manager -> Package Manager Console

To Remove:

UnInstall-Package EntityFramework

To Reinstall:

Install-Package EntityFramework

I hope this works for you as well

R. Bandi
  • 113
  • 11
0

Ok I'm not exactly sure how I solved this problem but I figured that I should try to describe it. I started over my solution in the same way and created the entity model. Then instead of using the code in the providers tag from that article at dev.mysql.com (link above) I found this in my app.config:

<providers>
  <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
</providers>

I copied the same thing over to my web.config. Then I was able to create the controller with scaffolding.

Jaclyn Noga
  • 1
  • 1
  • 4
0

After 8 hours of struggle debugging EFPowerTools, I found at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\PrivateAssemblies was Mysq.Data and Mysql.Data.Ef6 which were a diffrent version [6.9.8] from the ones in my web config [6.10.9] i copied the versions in my bin 6.10.9 to the above PrivateAssemblies folder and every thing worked fine.