1. Create the Models folder in the project
2. Create the attribute class for the table in the Models folder: such as the user class.
3. Models folder creation DataContext Inherit DbContext class (you can choose to override the Onmodelcreating method)
Public dbset< table class name > re-name {get;set;}
Public DataContext (dbcontextoption<datacontext> option):(option) {}
protected override void Onmodelcreating (ModelBuilder ModelBuilder)
{
Base. Onmodelcreating (ModelBuilder);
}
4. Enter the project in CMD and start creating the database with Dotnet EF
Input dotnet EF migrations Add firstmigration
Then enter dotnet EF Database update to create the migration
The database is created successfully!
Note: dotnet EF command
dotnet (. NET Core) is a cross-platform implementation of. NET. You can learn about it here.
dotnet EF Migrations Add Initial runs the Entity Framework. NET Core CLI Migration command and creates an initialization migration. The parameter "Initial" can be any value, but this is usually used as the first (initial) database migration. This action creates a *data/migrations/_initial.cs* file that contains the migration command to add (or delete) the Movie table to the database.
dotnet EF Database Update dotnet EF DB update updates the databases with the migration we just created.
Third, Dotnet Core Code first CREATE Database