...

/

Scaffolding Models Using an Existing Database

Scaffolding Models Using an Existing Database

Learn about scaffolding in EF Core, which can be extended manually while retaining the ability to regenerate them without losing the extensions.

Scaffolding model

Scaffolding is the process of using a tool to create classes that represent the model of an existing database using reverse engineering.

Scaffolding tool

A good scaffolding tool allows us to extend the automatically generated classes and then regenerate those classes without losing our extended classes. If we know that we will never regenerate the classes using the tool, feel free to change the code for the automatically generated classes as much as we want. The code generated by the tool is just the best approximation.

Note: Do not be afraid to overrule a tool when we know better.

Comparing auto-generated models with manual creation

Let’s see if the tool generates the same model as we did manually:

Step 1: Add the latest version of the Microsoft.EntityFrameworkCore.Design package to the WorkingWithEFCore project.

Step 2: At a command prompt or terminal in the WorkingWithEFCore folder, generate a model for the Categories and Products tables in a new folder named AutoGenModels, as shown in the following ...

Access this course and 1400+ top-rated courses and projects.