This article solves two problems: one is the code generated by the Organization, but completes our program and implements basic functions.
Code generated by the Organization
By default, the designer generates a file and stores all the code in this file. This file is named after the designer file. The extension is. vb or. cs, depending on the language. For example, the model. edmx designer file creates a model. edmx. vb or model. edmx. cs. If you look at the code, you will find it messy. All classes are stored in a file, and there are many attributes and methods. Worse, classes are inherited from EntityObject, and the relationships between classes are represented by EntityCollection and EntityReference. The following describes a method to effectively organize code: the plain old CLR object (POCO) method.
1. In VS, select Tools> Extension Manager.
2. In the Extension Manager window, select the Online Gallery tab on the left, enter POCO in the search box in the upper right corner, and press Enter. For example:
3. Because I have already installed it, there is a green icon in the upper right corner. If it is not installed, click Download to install it.
After the installation is complete, follow the steps below to optimize the code.
1. right-click the designer, select Add Code Generation Item, and select ADO. net poco Entity Generator, and enter Entities in the Name text box. tt: Click OK. The two files are added to the project: Entities. tt and Entities. context. tt.
2. Select the two files, right-click and select Run Custom Tool to complete code optimization.
3. Right-click the designer, select Properties, and set Code Generation Strategy to None. In this case, only the following prompts are displayed in Model. Designer. cs:
As mentioned in the prompt, if you want to use the Default Code Generation method, set Code Generation Strategy to Default.
BASIC program implementation skills
1. set OrderIT. app in Model. copy the <add name = "OrderITEntities" connectionString = "'"/> node content of the Config file in OrderIT. web. <connectionStrings> </connectionStrings> node in Config.
2. Add the Controller. In the Add Controller dialog box that appears, enter.
3. Click Add to run the program.
Written at the end
In this example, due to a small problem with the previous model design, I re-designed it, but I forgot to set the Abstract attribute of the Company object to True, it took a lot of time to find the cause. I marked it in the previous article. In fact, the above example is not appropriate, because all the knowledge points in the back should be explained in detail, so it will not take too much time here.
If you need source code, click to download it.