MVC Learning Database Development model: Three types of development model summary:

Source: Internet
Author: User

Let's introduce the following three ways to use the development model:

1, Database First:

database development: Database Priority main steps: 1 , establishing a database in the database, and the required tables . 2, select the Models folder, add new project-data-ADO. NET Entity Data Model ... On the Build Database page select Generate from Database   after completion 2, the database connection string 3 is automatically generated in Web. config , the controller is created and the corresponding view page 4, Creates a data context instance object in the controller that is created by the name of the connection database string.

2, Code First:

code-First Steps for database development: 1 , create the corresponding class for the required table in the Models folder 2 , establishing the database context class in the Models folder, inheriting the DbContext class 3 , add the node for the linked database in the Web. config file. Note that the node name is the name of the data context class, the database name takes 4, add the controller and the corresponding view interface.  5, in the controller to create an instance of the data context class 6, using the class can manipulate the database data 7, After build, you can see the generated database in the database. Tables in the database automatically set the primary key.

3, Model first:

database Development mode: Model First1, create an empty database in the database2, and establish the ADO Entity Data model in the Models folder. Generate Database page Select an empty model3, on the. edmx file page--right---Properties--Modify the Entity container name "The name and the name of the database connection node in the configuration question and the name of the data context class are the same"4, on the. edmx file page--right--new additions--entity "is a table"--Modify entity set name "Change name is the name of the new table"5, on the attribute of the entity--right--new addition--scalar attribute "is to add attribute field to table"6, on the. edmx file page--right--to generate a database from the model--Finally, a SQL file is generated7, on the SQL file page--Right click--Connect--connect, on the SQL file page--right--Execution8, and the database is established. The next step is to create a database context instance and manipulate the data Object! 
Summary:
Using database precedence and model precedence does not require the developer to establish the class and database context corresponding to the tables in the database itself. are automatically generated through the ADO entity Database model.
The difference between this two development model is the creation of a table in the database:
1, Database First: Need direct contact with the database, all the tables and the primary key settings are in the database
2, Model first: Do not need direct contact with the database, all the entity "table" design and the primary key settings are done in development tool vs. However, it is also necessary to establish an empty database in the database, if you do not choose to connect to the database, the default is to create a table in the master database

Use code First: Although developers are required to write their own classes and write classes on the database. and the Configuration database connection node, but it is completely free from direct contact with the database. When the corresponding class of the table is written, the database context class is created and the node is configured well. The database can be manipulated directly using context instance objects. After the build, the database is automatically generated! There is no need to establish a database beforehand.

Write blog, convenient and convenient for people who need!

MVC Learning Database Development model: Three types of development model summary:

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.