I have scaffolded my database into models using the following command:
dotnet ef dbcontext scaffold "Server=.\;Database=MyApp;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -o Models
Whenever there is a db change I fire the above command with the -force flag.
This has auto generated the dbcontext and class files representing the tables into the models folder.
My question:
In the dbcontext.cs file, in addition to the class constructor and dbset, there are the following methods generated:
- OnModelCreating
- OnModelCreatingPartial
What is the purpose of these methods and can I get rid of them.
For example: In the program.cs I am planning to add:
builder.Services.AddDbContext<MyAppContext>(opt =>
opt.UseSQLServer(".\;Database=MyApp;Trusted_Connection=True;"));
So I can remove the OnConfigurimg method. What about the above 2 methods?
I want to create some models, for example additional tables and identify tables that I want to migrate into the database. So I'm confused with how to proceed due to the presence of those functions.