Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework 6.3 with ASP.NET Core 3

How do I would use Entity Framework 6.3 with ASP .NET Core 3? Specifically, I wish to generate a model from an existing database. It does not appear that I can add an Entity Data Model unless I target the full .NET Framework (however, isn't Entity Framework 6.3 supported on .NET Core 3?)

like image 602
Muaddib878 Avatar asked Sep 24 '19 07:09

Muaddib878


People also ask

Can we use Entity Framework 6 in asp net core?

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.

Is .NET Core 3 supported?

NET Core 3.1 was originally released on December 3, 2019 and is supported for three years. But the actual end of support day will be the closest Patch Tuesday starting that date, which is December 13, 2022.

Is Entity Framework 6 still supported?

Versions 6.0, 6.1, 6.2, and 6.3 are no longer supported. Although Entity Framework 6. x is still supported, it is no longer being developed and will only receive fixes for security issues.

Is .NET Core 3.1 cross-platform?

NET Core is cross-platform. It runs on Windows, OS X and multiple distributions of Linux. It also supports different CPU architectures.


2 Answers

If I understand correctly your question, you want to generate the model from the tables of your database, using .Net Core with Entity Framework.

You can do this by using Entity Framework Core and Tools packages in your project.

  dotnet add package Microsoft.EntityFrameworkCore.SqlServer
  dotnet add package Microsoft.EntityFrameworkCore.Design

And the dotnet ef dbcontext scaffold

Example:

    dotnet ef dbcontext scaffold "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o Models

Per the designer support for EF 6.3, I think you are out of luck:

This is the recommended approach from Microsoft at the moment:

How to work with EDMX files in .NET Core projects On the tooling side, we plan to release an updated EF6 designer in an upcoming update of Visual Studio 2019 which will work with projects that target .NET Core (tracked in issue #883).

Until this new version of the designer is available, we recommend that you work with your EDMX files inside projects that target .NET Framework. You can then add the EDMX file and the generated classes for the entities and the DbContext to the .NET Core 3.0 or .NET Standard 2.1 project as linked files.

https://github.com/efcore/EdmxDotNetCoreSample/

like image 149
Athanasios Kataras Avatar answered Sep 19 '22 17:09

Athanasios Kataras


You can use Visual Studio to reverse-engineer EF6 code-first models from a database, but I don't believe it's enabled by default in a .NET Core project. However, you can generate the models in a .NET Framework project and either copy the files or convert the project to .NET Core later.

If you have the Entity Framework 6 Tools component installed in Visual Studio, then from a .NET Framework project you should be able to Add -> New Item -> ADO.NET Entity Data Model. This kicks off a wizard to choose which tables should have models generated.

(I think this has been around since at least VS 2017 - I assume we're using VS 2019 because of EF 6.3 / .NET Core 3.0.)

like image 39
Blake Avatar answered Sep 20 '22 17:09

Blake