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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With