简体   繁体   English

带有MySQL数据库的ASP.NET 5 / MVC 6

[英]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. 我计划构建一个将在Linux上托管的MVC 6网站,我目前正处于初始测试阶段,看看新的ASP.NET 5(vNext)和MVC 6是如何工作的,以及我是否可以在Linux上部署所有内容。

My website must make use of a database and since it will be deployed on Linux obviously I cannot use SQL Server. 我的网站必须使用数据库,因为它将部署在Linux上,显然我不能使用SQL Server。 I would very much like to use MySQL but maybe there are other alternatives? 我非常想使用MySQL,但也许有其他选择? Let's just say for now I need MySQL, unless it is not possible. 我们现在只说,我需要MySQL,除非它不可能。

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. 我很快发现,实体框架7还没有MySQL连接器,这是MVC 6使用的。 Does this mean I am out of luck and will have to wait until a new MySQL connector comes out with support for EF7? 这是否意味着我运气不好,必须等到新的MySQL连接器出来支持EF7? Or can I possibly revert to EF6 in an MVC 6 website, which does support MySQL? 或者我可以在MVC 6网站中恢复到EF6,它支持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. 我尝试将依赖项添加到EF6但是在默认的MVC 6模板中有很多依赖项,所有引用EF7我完全丢失了,并且根本不知道如何处理它,如果它甚至可能的话。

So to summarize: 总结一下:

  • Can I use EF 7 with MySQL already, or do I have to wait until a new MySQL Connector supports this? 我可以将EF 7与MySQL一起使用,还是必须等到新的MySQL Connector支持这个?
  • Can I fall back to EF6 and still use MVC 6 and deploy on Linux (using Mono)? 我可以回退到EF6并仍然使用MVC 6并在Linux上部署(使用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? 如果所有其他方法都失败了 - 我可以在Linux / Mono上使用与MVC 6不同的数据库吗?

I'm aware of 2 solutions for you. 我知道有两种解决方案。 SQLite and Postgres. SQLite和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). SQL Server仍然是EF 7中受支持最多的数据库。这应该可以在Mono中运行,但不幸的是需要使用Windows Server(或SQL Azure)。

SQLite SQLite的

在此输入图像描述

Not ideal for servers, but still works : The EntityFramework.Sqlite is in development for EF 7. You can get beta1 from Nuget.org. 不适合服务器,但仍然有效 :EntityFramework.Sqlite正在开发EF 7. 你可以从Nuget.org获得beta1。 This should work on Mono. 这应该适用于Mono。

PostgreSQL PostgreSQL的

Npgsql.EntityFrame

Definitely pre-release, but is being build : Also, Postgres ( npgsql ) are developing on EF7 provider. 绝对是预发布,但正在构建 :此外,Postgres( npgsql )正在开发EF7提供程序。 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.) 他们的代码是onGitHub ,您可以从他们的MyGet源获取预发布包(将https://www.myget.org/F/npgsql-unstable添加到您的Nuget源。)

Can I use EF 7 with MySQL already, or do I have to wait until a new MySQL Connector supports this? 我可以将EF 7与MySQL一起使用,还是必须等到新的MySQL Connector支持这个?

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. 目前没有支持MySQL的EF7模块,我相信我确信这是团队有兴趣为社区驱动的为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)? 我可以回退到EF6并仍然使用MVC 6并在Linux上部署(使用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. 你应该能够,你将无法使用CoreCLR,但我的理解是你仍然可以在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. 现在我注意到一些事情(我认为或Jabbr或博客,不确定),一旦CoreCLR支持linux和Mac 100%,这将是运行ASP.NET应用程序的唯一方式,但我再次不确定这个。

If all else fails - can I use a different database with MVC 6 on Linux / Mono? 如果所有其他方法都失败了 - 我可以在Linux / Mono上使用与MVC 6不同的数据库吗?

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. 目前除了EF7之外没有任何东西可以支持CoreCLR,但我确信随着我们前进,您将看到针对MySQL,Mongo,Raven等的coreclr重新编译的C#库。

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. 我试图在2015年12月30日更新这个问题,因为问题发布以来在ASP.NET 5空间中已经开发了很多。 At the time or this post we are in the final release update 1 (1.0.0-rc1-final-update1). 在本文或本文中,我们处于最终版本更新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. 这是一个sqlite选项: http ://damienbod.com/2015/08/30/asp-net-5-with-sqlite-and-entity-framework-7/使用EF7和SQLite。 Not sure if this is Linux ready... 不确定这是否已准备好Linux ...

"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 . 另一种选择是使用EF6以及ASP.NET 5和MVC 6,请阅读这篇文章: http//dan.cx/2015/08/entity-framework-6-mysql-aspnet This is Linux ready. 这是Linux准备好了。

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. 我鼓励人们继续更新这个问题,因为社区和Microsoft仍在为ASP.NET 5 MVC 6应用程序开发基于Linux的解决方案。

The SQLite option is Linux and OS X ready. SQLite选项是Linux和OS X准备好的。 (dnxcore support) (dnxcore支持)

http://damienbod.com/2016/01/07/experiments-with-entity-framework-7-and-asp-net-5-mvc-6/ 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/ http://damienbod.com/2015/08/30/asp-net-5-with-sqlite-and-entity-framework-7/

EF6 solutions are not, only runs on .NET. EF6解决方案不是,只能在.NET上运行。

EF7 and ASP.NET 5 should be production ready in Q1/Q2 2016, not definite, no date has been set. EF7和ASP.NET 5应该在2016年第一季度/第二季度生产就绪,不确定,没有设置日期。

PostgreSQL looks like a good solution for your problem. PostgreSQL看起来像是一个很好的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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