Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to scaffold EF core to existing DB?

I am trying to reverse engineer an existing database using Entity Framework Core. I tried to follow the directions from Microsoft but I am presented with the error:

Unable to find provider assembly with name EntityFramework. Ensure the specified name is correct and is referenced by the project.

I am running the following command from the project directory:

dnx ef dbcontext scaffold "Server=REMOVED;Database=REMOVED;User ID=REMOVED;Password=REMOVED" EntityFramework

What am I doing wrong?

like image 724
Matthew Verstraete Avatar asked Feb 09 '16 20:02

Matthew Verstraete


People also ask

How do I re Scaffold database in asp net core?

If you need to re-scaffold the model after database schema changes have been made, you can do so by specifying the -f or --force option e.g.: dotnet ef dbcontext scaffold "Server=. \;Database=AdventureWorksLT2012;Trusted_Connection=True;" Microsoft. EntityFrameworkCore.

What is Scaffold-DbContext?

The above Scaffold-DbContext command creates entity classes for each table in the SchoolDB database and context class (by deriving DbContext ) with Fluent API configurations for all the entities in the Models folder.


3 Answers

Install fallowing NuGet package:

Install-Package Microsoft.EntityFrameworkCore.SqlServer
like image 53
Amirhossein Yari Avatar answered Oct 10 '22 01:10

Amirhossein Yari


Make sure you are in the project folder and not the solution folder context. I was able to get this to work with the following yesterday (Notice the EntityFramework.MicrosoftSqlServer at the end)

dnx ef dbcontext scaffold "{connectionString}" EntityFramework.MicrosoftSqlServer

EDIT:

Make sure to include the following in your project.json:

EntityFramework.MicrosoftSqlServer.Design
like image 28
Matt Sanders Avatar answered Oct 10 '22 03:10

Matt Sanders


I was getting the following error when trying to scaffold from an existing SQLite database:

Unable to find provider assembly with name Microsoft.EntityFramworkCore.Sqlite. Ensure the specified name is correct and is referenced by the project.

The project was in a solution with one other project. Even though the correct project was referenced in the Package Manager Console it only worked when I selected the 'Set as Startup Project' item on the project context menu.

like image 22
John Avatar answered Oct 10 '22 02:10

John