Asp.net mvc3-database and Model

Source: Internet
Author: User

Next to "Asp.net mvc3-data transfer", we will add some classes to manage the book information in the database in this section. These classes will become our MVC applicationsProgramIn the "model" section.

We will use a. NET Framework data access technology called "Entity Framework" to define these model classes and use these classes for operations. First, you need to create a database. This tutorial does not explain how to use the sqlserver database. If you do not understand the database knowledge, you can refer to the tutorial section of the database, the following lists the sqlserver data table structure and basic data information.

Bookinfo data table structure

Bookinfo data table content

After the database is created, create the edmx file in vs2010, select the models directory of the solution, right-click the solution, add a new project, and select "ado.net object data model"

Create an edmx File

Next, select "generate from database"

Next, create a database connection and save the connection string to the Web. config file.

Next, select the data table

Click Finish. The effect of the designer is as follows:

Now, the books. edmx file has been added to the solution. Next, create the data access interface ibooks and put the interface file under the models directory.CodeAs follows:

Next, create the booksrepository class of data types under the models directory to implement the ibooks interface. The specific statement is as follows:

If you want to view and process data from a database, you do not have to write data similar to the data access code shown above according to the interface-oriented programming idea, however, there must be a basic data access layer development concept. In the next section, we will create a new bookscontroller class to display data in the database and allow users to create a book list.

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.