Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mono Entity Framework 6 MySQL

I have developed a project with Entity Framework 6 that use a MySQL as database.. On my windows system the project is working. Now I tried to move that project on my linux machine. In order to run the project I added the MySQL dll to the GAC and to machine config. All needed dlls are also located in the project folder. When the Entity Framework access the database I am getting the following error:

System.Configuration.ConfigurationErrorsException: Failed to find or load the registered .Net Framework Data Provider.
  at System.Data.Common.DbProviderFactories.GetFactory (System.Data.DataRow providerRow) [0x00000] in <filename unknown>:0

<?xml version="1.0" encoding="utf-8"?>
<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>
  <connectionStrings>
    <add name="CashDeskServerContext" providerName="MySql.Data.MySqlClient" connectionString="server=localhost;
      port=3306;database=ServerContext;uid=root;password=password;Convert Zero Datetime=True"/>
      <add name="AuditLogContext" providerName="MySql.Data.MySqlClient" connectionString="server=localhost;
      port=3306;database=AuditLogContext;uid=root;password=password;Convert Zero Datetime=True"/>
  </connectionStrings>
  <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>
</configuration>

Any ideas?

THX Michael

like image 368
Michael Avatar asked Mar 03 '14 10:03

Michael


People also ask

Can I use Entity Framework with MySQL?

MySQL Connector/NET is compatible with multiple versions of Entity Framework Core. For specific compatibility information, see Table 7.2, “Connector/NET Versions and Entity Framework Core Support”.

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.

What is MySQL data Entityframework?

Entity Framework is the name given to a set of technologies that support the development of data-oriented software applications. MySQL Connector/NET supports Entity Framework 6.0 (EF6 or EF 6.4) and Entity Framework Core (EF Core), which is the most recent framework available to .

Can we use Entity Framework 6 in asp net core?

To use Entity Framework 6, your project has to compile against . NET Framework, as Entity Framework 6 doesn't support . NET Core. If you need cross-platform features you will need to upgrade to Entity Framework Core.


1 Answers

This is because you don't seem to have the MySql ADO.NET provider configured. Take a look at my blogpost about using EF6 and MySql on Mono which shows how to resolve this exact issue (note that I wrote this post for pre-release EF6 version and the issues I hit on the road should be now fixed). Note that in the post I used DevArt MySql provider so you will have to find the correct entries to use for your provider. Also take a look at this stackoverflow post - Custom .NET Data Providers - which provides details on registering ADO.NET providers (you are most interested in DbProviderFactories part because this is what you are missing)

like image 128
Pawel Avatar answered Sep 23 '22 21:09

Pawel