5

Right now, the only way (as far as I know) to scaffold a database is via the command: Scaffold-DbContext .....

This does not scaffold tables without primary keys or views and does not run if there are any errors in your code. Also, I believe in order to update one table, you have to scaffold the entire database again (correct me if I'm wrong)

Will we see something like .edmx files in past ASP.NET versions? Something with a GUI or just less error-prone?

Is there another way to do it that I've missed?

3
  • Scaffolding is more meant to be a one-time command to generate the model files and then go on with code-first approach. Afaik no plans for .edmx. I think it was considered to be very difficult and problematic and hard to make it work with SCM, so unless there is a really huge demand, its unlikely to ever come to EF Core Commented Nov 2, 2016 at 15:20
  • @Tseng that actually makes a ton of sense that scaffolding is meant more of a one-time code. Are there any commands that come to mind if I wanted to update just one table? Commented Nov 2, 2016 at 15:52
  • @Daath I usually specify a separate output folder, copy it in myself then make sure I update the context to the new one which will also appear in the new context you generated in the other folder. Commented Feb 17, 2024 at 18:28

1 Answer 1

11

We can Scaffold the entire database tables with following Package Manager Console Command

Scaffold-DbContext "Server=yourserver;Database=database;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Model or 'D:\VSProject\Model' 

To Scaffold one table

Scaffold-DbContext "Server=yourserver;Database=database;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Model -t table-name  

To Update the existing table

Scaffold-DbContext "Server=yourserver;Database=database;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Model -t table-name -force -verbose
Sign up to request clarification or add additional context in comments.

1 Comment

Last time I tried to specify tables, the context was regenerated with only that table.. ugh.. so I usually just specify another output directory and bring it in myself, with the updated definition in the new context.

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.