如何将EF6与ASP.NET Core 1结合使用 [英] How to use EF6 with ASP.NET Core 1

查看:173
本文介绍了如何将EF6与ASP.NET Core 1结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个ASP.NET Core 1项目,并使用.Net Core 1.0框架.并想使用实体框架6 .
我遵循本教程 https://docs.efproject.net/en/latest/platforms/aspnetcore/new-db.html ,当我尝试使用以下语句进行迁移时:

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

然后它告诉我:

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

是否可以将EF6与ASP.NET Core 1一起使用?

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

推荐答案

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

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

内部project.json:

Inside project.json:

  • 从目标框架中删除netcoreapp1.0并添加net451.
  • 删除所有EF Core,并将Migrator.EF6.Tools + EF6添加到您的依赖项中
  • Remove netcoreapp1.0 from the target frameworks and add net451.
  • Remove everything EF Core and add Migrator.EF6.Tools + EF6 to your dependencies

内部Startup.cs:

Inside Startup.cs:

  • 删除与EF Core相关的所有内容.
  • 只需将您的数据库上下文添加到服务:services.AddScoped<ApplicationDbContext>();
  • Remove everything EF Core related.
  • Simply add your db context to services: services.AddScoped<ApplicationDbContext>();

下一步:

删除EF Core生成的迁移"或数据/迁移"文件夹.

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

最后:

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

请注意,您可以使用另一个名为 MR.AspNet.Identity.EntityFramework6 将Asp.Net核心身份与实体框架6桥接起来.

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

这篇关于如何将EF6与ASP.NET Core 1结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆