EF's Modelfirst entity first

Source: Internet
Author: User

Following the last blog post written in Dbfirst, the following about Modelfirst knowledge, Modelfirst as the name implies, the entity first!

For the first time in the design entity, there is no prototype of the database table, so the developer can design the entity while generating the database table, double benefit. Here are the steps to talk about Modelfirst:

First build a console application (similar to Dbfirst steps)



New as:


Add New Item-Select the ADO Entity Data Model:




This is not the same as Dbfirst because Modelfirst does not have a database and chooses an empty model:


as shown in the following:



Right-click in the blanks and select entity creation:



Select New Entity :



New class entity:



then add the attribute Classnumber for the class entity:



then add the student (Student) entity:



finally establish the relationship between class and student (one-to-many relationships):



the diagram for the two entities is as follows:



then select Entity All, right-click to select Build database:



Select the database on which server to build the table, and the name of the table:



Select Yes, and then click Next:




Finally, the SQL script is generated in VS, and the Execute SQL script automatically builds the table in the database:



The resulting table is as follows:



the entities in the table are as follows:




about Modelfirst If you modify the Entity data, we can use the EF mechanism to modify it, and then synchronize the database, but if you modify a field, use Modelfirst to modify it, and then generate the SQL script to regenerate the table (provided that the data in the database is backed up. Otherwise it will be emptied), or you can modify the field directly in the database and then use Dbfirst to generate the entity? Still need to study, we can also actively shoot bricks!



EF's Modelfirst entity first

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.