In the previous article, we mainly introduced mvc3 and project creation. In this article, we will mainly look at the creation of the Entity Data Model in mvc3. When creating a project, we use. net 4, in. in net 4, we can use Entity Framework (Entity Framework) to create models, so as to prepare us for adding, deleting, modifying, and querying database data.
Right-click the models folder and choose add new item. We will add the ADO. Net object data model named androiddb. edmx. We should standardize and make sense in naming, which will facilitate subsequent operations. For example:
In the following pop-up form, select "generate from database" for the model content and "Next" for the model content. Next, select data connection, select a database in the new connection, enter the corresponding user name and password to connect to the database, and name the connection string androidentities. After the connection is complete, we can go to the Web. find the connection string name in config. For example:
Next, select the database object as an entry-levelArticleFor the sake of simplicity, we only select the table object. we name the model namespace androidmodel. For example:
Here, we have created an object data model. Double-click androiddb. edmx to view the classes corresponding to each table. For example:
The Entity Framework automatically creates classes for tables in the database and adds these classes to our project. Similar to the process of creating an entity layer using the dynamic software tool, we double-click androiddb. designer. CS shows the C # class corresponding to each table.
This article describes how to create an object data model. Using the Entity Framework, we will read and display the article table (Article) in the next article, which will mainly involve control operations, this is what we need to focus on.