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.