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