How to use EF6 with ASP.NET Core 1

asp.net asp.net-core c# ef-migrations entity-framework-core

Question

I created an ASP.NET Core 1 project and using .Net Core 1.0 framework. And want to use the Entity Framework 6.
I follow this tutorials https://docs.efproject.net/en/latest/platforms/aspnetcore/new-db.html and when I try to migrate with the statement:

PM> Add-Migration MyFirstMigration

then it shows me:

The EntityFramework package is not installed on project 'IndustryCloud'.

It is possible to use EF6 with ASP.NET Core 1?

1
4
7/8/2016 1:50:30 PM

Popular Answer

You can use Entity Framework 6 with ASP.Net Core 1.0. An example application can be found on Github.

In order to make it work, you have to follow the instructions from the repo (below I paste the crucial parts, but I encourage you to check the ones from repository):

Inside project.json:

  • Remove netcoreapp1.0 from the target frameworks and add net451.
  • Remove everything EF Core and add Migrator.EF6.Tools + EF6 to your dependencies

Inside Startup.cs:

  • Remove everything EF Core related.
  • Simply add your db context to services: services.AddScoped<ApplicationDbContext>();

Next:

Remove the "Migrations" or the "Data/Migrations" folder that EF Core generated.

And finally:

dotnet ef migrations enable
dotnet ef migrations add InitialCreate
dotnet ef database update

Note that you can use another project called MR.AspNet.Identity.EntityFramework6 to bridge Asp.Net Core Identity with Entity Framework 6.

3
7/8/2016 1:39:40 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow