Add Model
In this section, we will add some classes to manage movie materials in the database. These classes are
ASP. net mvc program model section.
You will use the. NET Framework data called the Entity Framework.
Access Technology to define and use these classes. Entity Framework (usually referred to as EF) Support
A development mode called Code First. Code priority allows you
Create model objects by writing simple classes. (These classes are called POCO objects,
From purely old CLR object "plain-old CLR objects.") Then you can
Using these entity classes to dynamically create databases makes the development process concise and efficient!
Add model class
In solution resource management, right-clickModelsFolder, select Add->
Class ....
The class is named "Movie ".
Add five attributes to the Movies class.
public class Movie{ public int ID { get; set; } public string Title { get; set; } public DateTime ReleaseDate { get; set; } public string Genre { get; set; } public decimal Price { get; set; }}
We use the Movie class to represent movies in the database. Each Movie instance represents a row in the data table,
Each attribute of the Movie class is mapped to a field in the data table.
Add the MovieDBContext class to the file.
public class MovieDBContext : DbContext{ public DbSet<Movie> Movies { get; set; }}
The MovieDBContext class represents the context of The Movie Database of the object framework. It
Processes Movie instances in read, store, and update data.MovieDBContext
Derived from the DbContext provided by the object framework.