Some people said that NCodeGenerate is good and has powerful functions. In the United States, the debugging function is too weak. If one-step execution is performed, you can set breakpoints and view variables, it is better to have the same debugging functions as Visual Studio. I said, "You asked too much. ". However, since NCodeGenerate uses the Razor template engine and finally generates C # code for execution, why cannot we use Visual Studio for debugging. Okay, just do it. Hard work, hard work, and hard work, finally succeeded! Thank you!
Not much nonsense, film:
Create a template and enter the following code:
@model DynamicCodeGenerate.myModel@{int i=0;Debugger.Launch();Debugger.Break();NTrace.WriteLine("Begin");foreach(var item in Model.DataBase.Tables){@:TableName:@item.Name foreach(var itemcolumn in item.Columns) { @:Column:@itemcolumn.Name } i++; }}
In the above Code,
Debugger. Launch ();
Debugger. Break ();
These two statements are very important. Debugger. Launch (); is required to start the Debugger. If this code does not exist, the debugger will be called up, but the debugging is complete. After the process is detached, the control cannot be handed back to NCodeGenerate, and NCodeGenerate will never be in the unresponsive state. If you start the debugger in advance and attach it to NCodeGenerate, you do not need it. In either case, the Debugger. Launch () Code does not play a role, so you can lose it.
Debugger. Break (); indicates that the Debugger has a breakpoint and stops waiting for your command.
Select the data source to execute. The following dialog box is displayed:
Select "yes ". The highlights are coming.
Familiar with the debugger, the C # code generated by NCodeGenerate is displayed. Well, I don't need to talk about the following things. You can set breakpoints, execute them in one step, and view variables here.
NCodeGenerate is completely exposed. All the code is displayed in front of you, and everything is under control.
The next article will introduce the principles and structure of the code generated by the Razor template engine.
Appendix: NCodeGenerate adds the NCodeGenerate. DBSchema document, which is connected in the following document.
Attached:
NCodeGenerate.zip
Document: Document
NCodeGenerate series of articles:
I. What is NCodeGenerate? Ii. Code Generation Tool-NCodeGenerate tutorial (1) traverse all tables in the database III. Code Generation Tool-NCodeGenerate tutorial (2) code Generation Tool-NCodeGenerate tutorial (3) generate code to a file. 5. Code Generation Tool-NCodeGenerate tutorial (4) CodeSmith template conversion 6. Code Generation Tool-NCodeGenerate tutorial (5) support for multiple databases 7. Code Generation Tool-NCodeGenerate tutorial (6) NTrace output for debugging functions 8. Code Generation Tool-NCodeGenerate tutorial (7) unveil the mystery of the debugging function 9. Code Generation Tool-NCodeGenerate tutorial (8) unveil the secrets of the Razor template engine 10. Code Generation Tool-NCodeGenerate tutorial (9) Data Type ing Map function