1

I have an application in ASP web forms. I working on migrating this web form application to .net core 3.0. I am using database first approach as I have perfect tables structure, many store procedures and too much data. Today I add some new columns in data table 'Stock'. Columns name are:

  1. Color_ID. 2. Location_Id

I also add one new table 'Locations' in my database. Now the question is how can I update the DB context model class in my project for this two tables changes using database first approach in .net core.

1 Answer 1

5

Scaffold Context

Using the Package Manager Console

Scaffold-DbContext "your_connection_string" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Force

using CLI

dotnet ef dbcontext scaffold "your_connection_string" Microsoft.EntityFrameworkCore.SqlServer -o Models -f

Updating the Context

if you want to re-scaffold the model after making schema changes, you can do so by specifying the -force option e.g.:

dotnet ef dbcontext scaffold "your_connection_string" Microsoft.EntityFrameworkCore.SqlServer -force

All of the class files will be overwritten, which means that any amendments that you might have made to them e.g. adding attributes or additional members, will be lost.

Sign up to request clarification or add additional context in comments.

2 Comments

Saeed Gholamzadeh Sir, Will this commands also import my sql store procedures in the model context class. I mean only tables models will update or store procedures also?
in aspnetcore you can't scaffold context with db first store procedures instead, you can use context to call procedure like this approach: entityframeworktutorial.net/efcore/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.