简体   繁体   中英

Entity Framework 6 and .Net Core application

I have been reading about .Net core and this Link

https://docs.microsoft.com/en-us/aspnet/core/data/entity-framework-6?view=aspnetcore-2.2

It states

The recommended way to use Entity Framework 6 in an ASP.NET Core application 
is to put the EF6 context and model classes in a class library project that 
targets the full framework. Add a reference to the class library from the 
ASP.NET Core project.

However, when I actually do the following.

  1. Create Console Application based on .Net Core
  2. Create Class library based on .Net full framework.
  3. In class library , Add EDMX and link it with a sql database.
  4. Refer the class library in Core app .

It will not let me compile with the following error:

The Type DbSet is defined in an assembly that is not referenced.

This means I have to add an Entity Framework reference to the console app but it will not allow me to as a .Net Core app does not suppport the full entity framework.

Surely, I am missing something or getting the post mentioned above wrong.

Does anyone see the issue?

The link you provide is clear:

To use Entity Framework 6, your project has to compile against .NET Framework, as Entity Framework 6 doesn't support .NET Core. If you need cross-platform features you will need to upgrade to Entity Framework Core.

Create a new ASP.NET Core and target to full .NET instead of Core.

From Entity Framework 6.3 onward you'll be able to use EF6.x with .NET Core rather than having to switch to EF Core.

From Diego Vega's blog post Announcing Entity Framework 6.3 Preview with .NET Core Support :

What is new in EF 6.3?

While Entity Framework Core was built from the ground up to work on .NET Core, 6.3 will be the first version of EF 6 that can run on .NET Core and work cross-platform. In fact, the main goal of this release is to facilitate migrating existing applications that use EF 6 to .NET Core 3.0.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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