28

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.

Mark
  • 8,046
  • 15
  • 48
  • 78
  • 1
    Seeing as MariaDB is a political fork, they'd be insane to break compatibility with MySQL's wire protocol though. It's probably easier to maintain compatibility than maintain an entire family of client software. They also expressly say this in the docs: https://mariadb.com/kb/en/mariadb-versus-mysql-compatibility/. – millimoose Nov 25 '13 at 02:20
  • I don't have the resources to virtualized a RedHat server with MariaDB. What I have tried is a MySQL on a RedHat server. – Mark Nov 25 '13 at 02:22
  • You can't download VirtualBox, install CentOS, and MariaDB into that, and point a sample project at that DB? – millimoose Nov 25 '13 at 02:23
  • Good idea but I can't with my machine's specs. And that is not what I'm asking for. – Mark Nov 25 '13 at 03:08
  • 1
    Well it's something that will have to be done anyway. Nonetheless, seeing how their docs expressly say that "mid-level" interfaces (i.e. published APIs, not data file formats and internal stuff) are compatible, the high level ones really should be as well. EF breaking would be a bug. – millimoose Nov 25 '13 at 11:36
  • try http://brice-lambson.blogspot.in/2012/10/entity-framework-on-mysql.html – VahidN Dec 20 '13 at 06:12

1 Answers1

17

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.

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
  • There is some kind of support now (VS2013 & MySQL), but it's a pain. I ended up creating EF with 2012, and then using 2013 for development. – Noctis Apr 16 '14 at 02:58
  • And then you have a GPL-application, btw. - if you don't have a commercial license for the GPL (not LGPL) MySQL connector. – Stefan Steiger Sep 15 '17 at 08:50
  • @StefanSteiger the "official" connector has so many serious problems (eg fake async calls) that people started their own projects in the last 3 years. [MySqlConnector](https://github.com/mysql-net/MySqlConnector) seems to be the most popular ADO.NET provider and [Pomelo](https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql) offers EF support on top of it. It looks like *Oracle* doesn't care that much about MySQL (for .NET I mean) – Panagiotis Kanavos Sep 15 '17 at 08:55
  • @Panagiotis Kanavos: I would use the mariadb-connector instead, works for MySQL as well: https://github.com/noahvans/mariadb-connector-net But interesting via Pomelo if you use EF. – Stefan Steiger Sep 15 '17 at 11:26
  • @StefanSteiger it looks abandoned. The last commit was 2 years ago and the last build failed – Panagiotis Kanavos Sep 15 '17 at 11:33
  • @Panagiotis Kanavos: Yea, just noticed that too. MySqlConnector then. Might be a modified version of an old version of MySqlConnector, but that's just a guess. – Stefan Steiger Sep 15 '17 at 11:38
  • Three years later, and it seems that things have changed and updated. A possible update to this answer? :) – FireController1847 Apr 10 '20 at 03:14
  • @FireController1847 the real difference is that MySqlConnector and Pomelo now have almost as many if not more downloads per month in NuGet as MySql.Data, but far more frequent updates. – Panagiotis Kanavos Apr 10 '20 at 07:16
  • Hey, thanks for the update. Yeah, I ended up using those and I finally managed to get a working version of everything, even if it wasn't quite as fluid as everything else .NET :P – FireController1847 Apr 10 '20 at 07:20