Entity Framework Core scaffold additional tables not context

c# entity-framework-core

Question

From Microsoft documentation:

https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db

When trying to reverse engineer your models and dbcontext from an existing database, you can run a command like this:

Scaffold-DbContext "Server=myserver; Database=mydatabase; Integrated Security=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Entities -Tables FirstTable, SecondTable 

This will create me two models and a dbcontext based on my connection details.

If I want to come back later and add another few tables, is it possible to run the same command, or something similar with different parameters that will not create the dbcontext again, as I already have this from my initial scaffold.

Currently we are running the command over and over again and deleting the context each time, or manually building any new models based on the database tables. It seems counter productive.

In Entity Framework 6 and below we would just maintain the edmx diagram but obviously this is not included in EfCore.

1
0
1/7/2019 4:34:51 PM

Accepted Answer

It's logged as a request with the EF Core team, but has been pending for a good while now.

Github link

1
1/7/2019 4:47:47 PM

Popular Answer

In EFCore, there really isn't support for database first design. The scaffolding feature is only meant to be a one-time operation to build your code first models/contexts so that you don't have to hand code them in order to get started using EF. Once run the first time, you should be moving to EF Migrations instead of scaffolding to deal with additions/updates/deletes to the schema.

Here is MS documentation for migrations: https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow