Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework 6 and .NET Core application

I have been reading about .NET Core and ASP.NET Core and Entity Framework 6.

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 a console application based on .NET Core
  2. Create Class library based on the .NET full framework.
  3. In the class library, add EDMX and link it with a SQL database.
  4. Refer to the class library in the .NET Core application.

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 ADO.NET Entity Framework reference to the console application, but it will not allow me to as a .NET Core application does not support the full Entity Framework.

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

What is the issue?

like image 554
Mandar Jogalekar Avatar asked Oct 20 '25 11:10

Mandar Jogalekar


2 Answers

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.

like image 66
tomRedox Avatar answered Oct 23 '25 00:10

tomRedox


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.

like image 37
Max Avatar answered Oct 23 '25 00:10

Max



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!