简体   繁体   中英

ASP.NET 5 / MVC 6 with MySQL database

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?

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

在此输入图像描述

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.)

Can I use EF 7 with MySQL already, or do I have to wait until a new MySQL Connector supports this?

There is no current module for EF7 that supports MySQL, that said I'm sure it's something the team would be interested having a pull request created for a community driven effort to build a module for EF. It's still early days, so who knows what will happen.

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?

You should be able to, you won't be able to use the CoreCLR, but my understanding is that you can still stand it up on Mono. Now I noted something (I think or Jabbr or a blog, not sure) that once the CoreCLR supports linux and Mac 100% that was going to be the only way to run a ASP.NET App, but again I'm not sure about this.

If all else fails - can I use a different database with MVC 6 on Linux / Mono?

There is nothing that supports CoreCLR except for EF7 at this moment in time, but I'm sure as we move forward you'll see C# libraries recompiled for coreclr for MySQL, Mongo, Raven, etc.

I am attempting to update this question on 12/30/2015 as much has developed in the ASP.NET 5 space since the question was posted. At the time or this post we are in the final release update 1 (1.0.0-rc1-final-update1).

This is a sqlite option: http://damienbod.com/2015/08/30/asp-net-5-with-sqlite-and-entity-framework-7/ using EF7 and SQLite. Not sure if this is Linux ready...

"EntityFramework.Commands": "7.0.0-rc1-final", "EntityFramework.SQLite": "7.0.0-rc1-final"

Another option is to use EF6 and with ASP.NET 5 and MVC 6, read this post: http://dan.cx/2015/08/entity-framework-6-mysql-aspnet . This is Linux ready.

I encourage people to continue to update this question as the community and Microsoft are still developing Linux based solutions for ASP.NET 5 MVC 6 applications.

The SQLite option is Linux and OS X ready. (dnxcore support)

http://damienbod.com/2016/01/07/experiments-with-entity-framework-7-and-asp-net-5-mvc-6/

http://damienbod.com/2015/08/30/asp-net-5-with-sqlite-and-entity-framework-7/

EF6 solutions are not, only runs on .NET.

EF7 and ASP.NET 5 should be production ready in Q1/Q2 2016, not definite, no date has been set.

PostgreSQL looks like a good solution for your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM