I have an existing site that uses ASP.NET MVC 4, Entity Framework 6 and MySQL. I'm trying to upgrade it to ASP.NET 5, but want to continue using Entity Framework 6 as Entity Framework is missing some features and does not yet support MySQL. How do I use EF6 in ASP.NET 5?
相关问题
- sqlyog export query result as csv
- Entity Framework Code First Migration
- NOT DISTINCT query in mySQL
- MySQL: conduct a basic search
- Entity Framework throws exception - Network Relate
Since Web.config is no longer used with ASP.NET 5, you need to use code-based configuration to configure it instead. To do so, create a new class that inherits from DbConfiguration:
The first part of the configuration is a hack to register the ADO.NET provider at runtime, by dynamically adding a new configuration entry to the
system.data
section. This is very hacky, but does appear to work correctly.Add the connection string to
config.json
rather thanWeb.config
:Modify the
DbContext
to use the correct configuration and connection string:Register
MyContext
in the dependency injection container inStartup.cs
:Then you can just use constructor injection to get
MyContext
into your controllers.More details in my blog post at http://dan.cx/2015/08/entity-framework-6-mysql-aspnet, and a sample project at https://github.com/Daniel15/EFExample