EF Model First, EFModelFirst

Source: Internet
Author: User

EF Model First, EFModelFirst

1. Add the ADO. NET object data model (edmx)

1. Add edmx to create a class library project, add a new item to the project, and select the data/ADO. NET object data model, as shown in. Click Add. In the Object Data Model Wizard window, select an empty EF designer model and click Finish. The edmx file is created successfully. 2. Add the entity model. Next, add the entity model to the edmx designer. Right-click the designer to add/entity, or drag an entity from the toolbox.
2. Add T4 template (including DbContext and Entity) 1. Add a new item to the T4 template project and select the data/EF 6.x DbContext generator, as shown in. In this case, two files are added to the project, xxx. Context. tt and xx. tt. One is the DbContext Context template and the other is the entity template. 2. Modifying the newly added T4 template of T4 does not work immediately. You must make relevant settings. This is very important. First, modify $ edmxInputFile $ to the specific edmx file name, including HwaDB. Context. tt and HwaDB. tt, as shown in. Second, modify the content of the DbContext constructor. The default value is as shown in figure before modification. The modified image is shown in. Make two changes: Enable delayed loading to false, and modify the HwaDBContainer constructor in HwaDB. Context. tt. 3. Generate table creation Script 1. Create a database connection in the edmx workspace right-click the menu and generate a database according to the model... to open the data generation wizard window, as shown in. Select New connection to open the Connection Properties window and create a new connection. Click "OK" to return to the database generation wizard window. Click "Next" To Go To The completion page. Click "finish" to generate the SQL script. In this case, an SQL script is automatically generated in the project, such. 2. Generate a table creation script and create a data table. Open the SQL script, click Run, or open and execute the script in SQL SERVER to create a data table.

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.