如何在ASP.NET Core 1中使用EF6

我创建了一个ASP.NET Core 1项目并使用.Net Core 1.0框架。 并希望使用Entity Framework 6
我按照这个教程https://docs.efproject.net/en/latest/platforms/aspnetcore/new-db.html ,当我尝试使用语句进行迁移时:

PM> Add-Migration MyFirstMigration 

然后它告诉我:

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

可以在ASP.NET Core 1中使用EF6吗?

您可以将Entity Framework 6与ASP.Net Core 1.0一起使用。 可以在Github上找到示例应用程序。

为了使它工作,你必须按照repo的说明(下面我粘贴关键部分,但我鼓励你检查存储库中的那些):

在project.json里面:

  • 从目标框架中删除netcoreapp1.0并添加net451。
  • 删除所有EF Core并将Migrator.EF6.Tools + EF6添加到您的依赖项

在Startup.cs中:

  • 删除EF Core相关的所有内容。
  • 只需将db上下文添加到services: services.AddScoped();

下一个:

删除EF Core生成的“迁移”或“数据/迁移”文件夹。

最后:

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

请注意,您可以使用另一个名为MR.AspNet.Identity.EntityFramework6的项目来与entity framework6桥接Asp.Net核心身份。

您不能将Entity Framework 6与.Net Core 1.0一起使用。 有一个专门为.Net Core 1.0开发的Entity Framework Core 1.0软件包。 您需要安装它以在.Net Core 1.0项目中使用。

https://blogs.msdn.microsoft.com/dotnet/2016/06/27/entity-framework-core-1-0-0-available/

使用Nuget Package Mangager Console安装。

PM> Install-Package Microsoft.EntityFrameworkCore.SqlServer

添加新的迁移(如果是第一个,它将添加必要的文件夹结构和类)

dotnet ef migrations add {MigrationName}

删除最近的迁移。

dotnet ef migrations remove

更新数据库的最新版本(应用所有迁移)

dotnet ef database update

http://benjii.me/2016/05/dotnet-ef-migrations-for-asp-net-core/

你可以在谷歌找到这么多文章。