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.