Asp.net MVC3.0 Getting Started Guide 4 Model

Source: Internet
Author: User

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.

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.