itmannz
itmannz

Reputation: 599

update model after scaffolding existing database EF core 2.X

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

Upvotes: 5

Views: 7601

Answers (1)

Amir
Amir

Reputation: 2052

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

Upvotes: 1

Related Questions