Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using MariaDB with Entity Framework

Tags:

Recently, I read a news that MariaDB is a drop-off replacement for MySQL since MySQL has unfriendly pricing for clustered/enterprise version according to Google.

Now I can't find anything relevant about EF for MariaDB on Google so I'm hoping someone knows about it. Is it ok to use MySQL driver for this since it is 100% compatible? Any thoughts?

Update

I just found out that RedHat is also switching from MySQL to MariaDB for it's default database management system. So it is necessary for my current project to switch it to MariaDB.

like image 981
Mark Avatar asked Nov 25 '13 02:11

Mark


People also ask

Does Entity Framework work with MariaDB?

Installing Entity Framework Core for MySQL & MariaDB It is updated Frequently, has lesser bugs, and also supports MariaDB.

Is entity framework compatible 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.

What databases does Entity Framework support?

EF Core works with many databases, including SQL Database (on-premises and Azure), SQLite, MySQL, PostgreSQL, and Azure Cosmos DB.

Does EF core support MySQL?

MySql is the most popular Entity Framework Core provider for MySQL compatible databases. It supports EF Core 3.1 (and lower) and uses MySqlConnector for high-performance database server communication. The following versions of MySqlConnector, EF Core, . NET Standard and .


1 Answers

I was able to use MariaDB 10 with Entity Framework although it required a bit of work mainly because the MySQL tools are a bit buggy.

To work with MySQL/MariaDB in Visual Studio 2010/2012,you need to install MySQL for Visual Studio using MySQL Installer. I used the Web version as I only wanted to download the connectors and the extensions. Once you do this, you can add connections to MariaDB and create EF models.

This is not enough to run your code though. First you need to add the MySQL Connector using NuGet.

Unfortuanetly, MySQL for Visual Studio adds a reference to an older provider version (mentioned here) and can't load the newer version. To fix this, I added the following section in my app.config:

<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 replaces the old reference with a new one. Note that I used

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

not

<remove name="MySql Data Provider"/> 

in the remove element.

Currently, MySQL for Visual Studio isn't supported in Visual Studio 2013

UPDATE - 2017

Connector/.NET is essentially stagnant, with the same problems it had in 2013, eg no true asynchronous calls. The "async" calls are fake - they are run on separate threads, defeating the very purpose of using async. That alone makes it unsuitable for web applications, where one wants to server as many requests as possible using the minimum number of threads/CPU.

Never mind about .NET Core support.

That's why in the past few years people have built their own, truly asynchronous providers. Some of the more popular ones are:

  • MySqlConnector offers a truly asynchronous provider for .NET and .NET Core
  • Pomelo offers EF Core support on top of MySQLConnector

With about 100K NuGet downloads each, frequent versions and active maintenance.

They aren't "official", but definitely worth trying

Lockdown Update - April 2020

It seems MySqlConnector and Pomelo have really taken off.

Connector/.NET finally released a couple of versions after almost two years with the latest, 8.0.19, getting 233K downloads.

MySqlConnector on the other hand, got 496K downloads for version 0.61.0. Minor updates are frequent, with the latest, 0.63.2 coming 8 hours before this post. That's probably a bit too frequent, but far better than 2 years.

I haven't checked features or MySql 8 compatibility yet. If I had to chose though (which I will probably do for a project next week), I'd start with MySqlConnector.

I suspect Connector/.NET will be forced to offer far more frequent updates going on, to keep pace with .NET Core releases, but that's just speculation at this point.

like image 133
Panagiotis Kanavos Avatar answered Oct 04 '22 08:10

Panagiotis Kanavos