Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update dbcontext scaffolding in ASP.NET 5 with EF Core?

I have an ASP.NET 5 EF Core (formerly EF 7) Database First project I'm working on. I've been able to scaffold my database contexts using dnx. Accessing the database in the project is now working well, however I'm wondering what the best process is to mirror changes as my database schema changes.

I've done database migrations using code first and I've updated contexts using an edmx file, but neither option applies here.

I can manually edit the entity files and add new ones to match database changes. Alternatively, I can wipe the dbcontext and its table classes and re-scaffold from scratch each time. However, I would prefer a more automated process, if one exists.

like image 765
Alec Menconi Avatar asked Feb 15 '16 18:02

Alec Menconi


People also ask

How do you update scaffolding?

Updating the Model 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.

How do I update ef core tools?

Update the toolsUse dotnet tool update --global dotnet-ef to update the global tools to the latest available version. If you have the tools installed locally in your project use dotnet tool update dotnet-ef . Install a specific version by appending --version <VERSION> to your command.


1 Answers

EntityFramework 7 (soon to be called Entity Framework Core 1.0) supports both creating models from existing database (Database-First) as well as creating database from models (Model-First).

For the initial release, only database creation from model and scaffolding from existing database are planed. Incremental "database-first" are not planned for initial release and it's still open if it will come yet.

What you can do however is to scaffold your database into code and then only use code and migrations to do future updates to the database schema.

EDMX (Model-First, but w/o Code-First) won't be supported at all.

like image 174
Tseng Avatar answered Oct 26 '22 13:10

Tseng