ASP.NET 5 / MVC 6 with MySQL database

Nick Thissen picture Nick Thissen · Feb 4, 2015 · Viewed 8.1k times · Source

I have plans to build an MVC 6 website which will be hosted on Linux, and I am currently in the initial testing phase to see how the new ASP.NET 5 (vNext) and MVC 6 work and whether I can deploy everything on Linux.

My website must make use of a database and since it will be deployed on Linux obviously I cannot use SQL Server. I would very much like to use MySQL but maybe there are other alternatives? Let's just say for now I need MySQL, unless it is not possible.

I realize all this is still in beta phase and not ready for production, but I'm just looking to do the initial setup to make sure everything is working before I start working on the actual website. I cannot do that if there's no database connection...

I soon found out that there is no MySQL Connector yet for Entity Framework 7 which is what MVC 6 uses. Does this mean I am out of luck and will have to wait until a new MySQL connector comes out with support for EF7? Or can I possibly revert to EF6 in an MVC 6 website, which does support MySQL? I tried adding depencies to EF6 but there are so many dependencies in the default MVC 6 template that all reference EF7 I am completely lost and have no idea how to approach this, if it's even possible at all.

So to summarize:

  • Can I use EF 7 with MySQL already, or do I have to wait until a new MySQL Connector supports this?
  • Can I fall back to EF6 and still use MVC 6 and deploy on Linux (using Mono)? If so, how do I set this up?
  • If all else fails - can I use a different database with MVC 6 on Linux / Mono?

Answer

natemcmaster picture natemcmaster · Jun 17, 2015

I'm aware of 2 solutions for you. SQLite and Postgres. Unfortunately, neither are suited for a production application as of today. Both projects are under active development. SQL Server is still the best-supported DB in EF 7. This should work from Mono, but unfortunately would require you use a Windows Server (or SQL Azure).

SQLite

enter image description here

Not ideal for servers, but still works: The EntityFramework.Sqlite is in development for EF 7. You can get beta1 from Nuget.org. This should work on Mono.

PostgreSQL

Npgsql.EntityFrame

Definitely pre-release, but is being build: Also, Postgres (npgsql) are developing on EF7 provider. Their code is onGitHub and you can get a pre-release package from their MyGet feed (Add https://www.myget.org/F/npgsql-unstable to your Nuget sources.)