008. Adding a model to an ASP. NET Core MVC app, 008. addingmvc

Source: Internet
Author: User

008. Adding a model to an ASP. NET Core MVC app, 008. addingmvc

Adding a model to an ASP. NET Core MVC app
Add a model to asp.net core mvc)
8-minute reading duration
Content
1. Add a data model class
Add a data model class
2. Scaffolding a controller
Controller Base Frame
3. Add EF tooling and perform initial migration
Add the EF tool and perform basic migration
4. Test the app
Test Application
5. Dependency Injection
Dependency Injection
6. stronugly typed models and the @ model keyword
Strong model and @ model keywords
7. Additional resources
Additional resources
By Rick Anderson and Tom Dykstra
In this section you'll add some classes for managing movies in a database.
In this section, we will add some classes for managing movies in db.
These classes will be the "Model" part of the MVC app.
These classes are the Model part of MVC.
You'll use these classes with the Entity Framework Core (EF Core) to work with a database.
We will use EF core to operate these classes and data on the DB.
EF Core is an object-relational mapping (ORM) framework that simplifies the data-access code that you have to write.
EF core is an object-link ing framework that simplifies the amount of code and code required for database operations.
For this tutorial you'll use SQLite, but EF Core supports analyze database engines.
In this tutorial, we use the SQLite database. Of course, EF core supports many types of databases.
The model classes you'll create are known as POCO classes (from "plain-old CLR objects") because they don't have any dependency on EF Core.
We will create some simple model classes because they have no dependency on EF core.
They just define the properties of the data that will be stored in the database.
Only define the field attributes to be stored in DB in the class.
In this tutorial you'll write the model classes first, and EF Core will create the database.
In this tutorial, we use the Code First mode, First define the class, and then use EF core to create a DB.
An alternate approach not covered here is to generate model classes from an already-existing database.
Another approach is to use the DB First mode to automatically generate a data model class with an existing DB.
For information about that approach, see ASP. NET Core-Existing Database.
View ASP. NET Core-Existing Database.

Related Article

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.