Third, Dotnet Core Code first CREATE Database

Source: Internet
Author: User
Tags dotnet

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.