Using MariaDB with Entity Framework

c# entity-framework mariadb mysql

Popular Answer

Despite needing some work, I was able to use MariaDB 10 with Entity Framework, primarily because the MySQL tools are a little glitchy.

Install for Visual Studio, MySQL using Installing MySQL in Visual Studio 2010/2012 before using MySQL/MariaDB. I simply wanted to download the connectors and extensions, therefore I used the Web version. Then you can build EF models and establish connections to MariaDB.

However, this is insufficient to execute your code. The MySQL Connector must first be added using NuGet.

Unfortunately, MySQL for Visual Studio has a reference to an outdated provider version (listed as here) and is unable to load the most recent version. I amended my app.config to include the following section to address this:

<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.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
   </DbProviderFactories>
</system.data>

This substitutes a fresh reference for the previous one. Noting that I did,

<remove invariant="MySql.Data.MySqlClient"/>

not

<remove name="MySql Data Provider"/>

in theremove element.

Currently, Visual Studio 2013 does not support MySQL for Visual Studio.

ADVANCED - 2017

The same issues that plagued Connector/.NET in 2013 still exist, such as the lack of genuine asynchronous calls. The "async" calls are bogus because they are executed on different threads, which negates the fundamental point of utilizingasync . For web applications, where the goal is to service as many requests as possible utilizing the minimum amount of threads/CPU, that fact alone renders it inappropriate.

Concerning.NET Core support, disregard it.

People have created their own, really asynchronous providers as a result in recent years. Among the more well-known ones are:

  • A genuinely asynchronous provider for.NET and.NET Core is provided by MySqlConnector.
  • EF Core support is provided by Pomelo in addition to MySQLConnector.

each with around 100K NuGet downloads, regular updates, and ongoing maintenance.

Although they are not "official," they are worth trying.

Update on Lockdowns for April 2020

It appears like Pomelo and MySqlConnector have really taken off.

After almost two years, Connector/.NET eventually released a few different variants, with the most recent version, 8.0.19, receiving 233K downloads.

On the other side, MySqlConnector received 496K downloads for version 0.61.0. The most recent minor update, version 0.63.2, was released eight hours before to this post. Probably a little too frequently, but still much better than every two years.

Features and MySql 8 compatibility have not yet been confirmed. But if I had to pick just one (which I probably will for a project due the next week), I'd go with MySqlConnector.

To keep up with.NET Core releases, I predict Connector/.NET will have to provide much more frequent updates going forward, although that is currently just conjecture.

11
4/10/2020 7:21:21 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow