5

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

13
  • Morning, welcome to stack, please read stackoverflow.com/help/dont-ask, stackoverflow.com/help/minimal-reproducible-example and stackoverflow.com/help/how-to-ask Commented Sep 24, 2019 at 7:45
  • This article will help you here. Commented Sep 24, 2019 at 8:06
  • Thanks Pedro - I've seen that article. It's for a preview edition and describes only code-first - not database first Commented Sep 24, 2019 at 8:16
  • @Muaddib878 you aren't asking about database first, you're asking about EDMX. first Even in EF 6.2, EDMX is not a recommended solution - it hasn't been for years. Code first and reverse engineering a database were added because EDMX was too cumbersome - every time you modified the database you'd have to update two models. Even if you started from the EDMX designer, you'd still have one more model to modify yourself. I'm using database first all the time - with code. I design the database then update my classes. Commented Sep 24, 2019 at 8:24
  • @Muaddib878 given that, adding EDMX support to .NET Core has a low priority, and is primarily a Visual Studio issue Commented Sep 24, 2019 at 8:25

2 Answers 2

7

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/

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

1 Comment

I didn't realize the question at first, sorry. If you want ot keep track, check github.com/aspnet/EntityFramework6/issues/1053 where there is a request for a tool like dotnet ef but has not materialized yet.
1

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

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.