4

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?

6
  • 1
    Is there any specific reason to not use EFCore? Commented Feb 6, 2019 at 8:41
  • 1
    yes, because i am trying this for a scenario where entity framework implementation can't be changed, but the project has to go to .net core Commented Feb 6, 2019 at 8:42
  • 1
    EF 6.3 will be supported in .NET Core 3 (currently in Preview 1): blogs.msdn.microsoft.com/dotnet/2018/12/04/… Commented Feb 6, 2019 at 9:22
  • @MandarJogalekar that's a rather unrealistic scenario. Moving to .NET Core means a lot has to change already. EF Core is the fully supported version going forward, EF 6.3 and later are essentially in maintenance mode Commented Feb 6, 2019 at 9:25
  • @MandarJogalekar it sounds like the real question is how to use EDMX, not EF 6. Database-First is available in EF Core and doesn't need an EDMX file. Even in EF6, you can reverse-engineer a database into code-first classes. EDMX is the EF 4-5 way of working. It's something you'll have to migrate away from anyway Commented Feb 6, 2019 at 9:30

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.