update model after scaffolding existing database EF core 2.X

entity-framework-core

Question

I am using EF core 2.X scaffolding existing database. I have generated models classes using "dotnet ef dbcontext scaffold" command and it generate model classes.

Database team has change some table I have to run "dotnet ef dbcontext scaffold" command again to generate model classes to pick only changes.

for example let say I have one table called "employee" has column id, name.

I run "dotnet ef dbcontext scaffold" to generate models

After that I changed employee table and add one more column called "address" in database. How can I scaffold command to pick changes only .

Note: I know after generating models I should use migration to change database but our db team is has changed db and unfortunately, I have to do this. and advice

1
4
1/18/2019 1:00:26 AM

Popular Answer

You can provide an optional parameter to the scaffolding command to update only the table you target.

Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=DatabaseName;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir DirectoryNameOfYourModels -Tables employee -f

If you are using .net core cli then use.

dotnet ef dbcontext scaffold "Server=(localdb)\mssqllocaldb;Database=DatabaseName;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o DirectoryNameOfYourModels -t employee -f
0
1/21/2019 4:22:01 AM


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