ASP. NET mvc3 instance (2) use entity framework to create an object data model

Source: Internet
Author: User

 

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.

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.