In this section, you will add classes for managing movies in the database. These classes are ASP. net mvc applications.Program.
You will use the Entity Framework Data Access Technology under the. NET Framework framework to work with the model class. The Entity Framework (EF) supports a development model called code first. Code first, you can create a model object by writing a simple class (called poco class for short, "plain-old CLR objects. You can use the class to create a database in real time to make the development process clean and fast.
Add model class
In Solution Explorer, right-click the models folder, select "add", select "class", and enter the class name "movie ".
Add the following five attributes to the movie class:
Using System; Using System. Collections. Generic; Using System. LINQ; Using System. Web; Namespace Mvcmovie. Models { Public Class Movie { Public Int Id { Get ; Set ;} Public String Name { Get ; Set ;} Public String Genra { Get ; Set ;} Public Decimal Price { Get ; Set ;} Public Datetime Date { Get ; Set ;}}}
We will use the movie class as the video data in the database. Each instance of the movie object corresponds to a row in a database table. Each attribute of the movie class is mapped to a column in the table.
Add the following moviedbcontext class to the same file:
Public ClassMoviedbcontext: dbcontext {PublicDbset <movie> movies {Get;Set;}}
The moviedbcontext class indicates the content of the video database of the object framework. It is responsible for processing instances in the database for obtaining, storing, and updating the video class. Moviedbcontext inherits from the base class dbcontext provided by Entity Framework.
To use dbcontext and dbset, you need to add the following using statement at the top of the file:
Using system. Data. entity;
Next, you will build a new moviescontroller class, which you can use to display the video data and allow users to create a new video list.
AllArticleNavigation
This series contains 10 articles translated from ASP. net mvc4 official tutorial, due to the concise description of this series of articles, the length is moderate, from an example to explain, the full text finally completed a small system for managing movies, very suitable for beginners ASP.. Net mvc4.
The original article is for 9 articles, and the translator splits 6th of them into 2
1. Introduction to ASP. NET mvc4
· Original address: http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/intro-to-aspnet-mvc-4
· Address: http://www.cnblogs.com/seawaving/archive/2012/12/03/2800210.html
2. Add a controller
· Original address: http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-a-controller
· Address: http://www.cnblogs.com/seawaving/archive/2012/12/04/2801949.html
3. Add a view
· Original address: http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-a-view
· Address: http://www.cnblogs.com/seawaving/archive/2012/12/04/2801988.html
4. Add a model
· Original address: http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-a-model
· Address: http://www.cnblogs.com/seawaving/archive/2012/12/05/2803012.html
5. Access the data model from the Controller
· Original address: http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/accessing-your-models-data-from-a-controller
· Address: http://www.cnblogs.com/seawaving/archive/2012/12/05/2803429.html
6. view the Edit Method and edit View
· Original address: http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/examining-the-edit-methods-and-edit-view
· Address: http://www.cnblogs.com/seawaving/archive/2012/12/05/2804100.html
Http://www.cnblogs.com/seawaving/archive/2012/12/06/2804590.html
7. Add fields for the movie model and database table
· Original address: http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-a-new-field-to-the-movie-model-and-table
· Address: http://www.cnblogs.com/seawaving/archive/2012/12/06/2805401.html
8. Add verification for the model
· Original address: http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-validation-to-the-model
· Address: http://www.cnblogs.com/seawaving/archive/2012/12/06/2806322.html
9. view the detail and delete Methods
· Original address: http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/examining-the-details-and-delete-methods
· Address: http://www.cnblogs.com/seawaving/archive/2012/12/10/2811064.html