Related articles Series
Eighth Back EF Schema ~ Import database annotations into model entity classes
21st Back EF Architecture ~ Add annotations to the entities generated by EF DbContext (T4 template app)
22nd Back EF Architecture ~ Add annotations to the entities generated by EF DbContext (T5 template app)
Hey, can't say, EF4 's TT template with comments, after upgrading to EF5 TT Template, comments are not universal, so, you have to study again, and then the operation method to share out, the Microsoft!
T4 template may be a bit messy, this in the T5 template has a good improvement, but I hope to solve the problem in the T5 has not been solved, that is, TT class file automatically get the EDMX model annotation problem, perhaps the developers do not need entity comments, HI!
1 Add Class Comments First
Find this line of code Writeheader (Codestringgenerator, FileManager);
Add our code below it:
String summary=string. Empty;foreach (var entity in typemapper.getitemstogenerate<entitytype> (ItemCollection)) { Filemanager.startnewfile (entity. Name + ". cs"); Beginnamespace (code); if (entity. Documentation!=null && entity. Documentation.summary!=null) summary=entity. Documentation.summary; else summary=entity. Name;#>
<#=codestringgenerator.usingdirectives (inheader:false) #>///<summary>///<#=summary#>///</ Summary><#=codestringgenerator.entityclassopening (Entity) #>
While saving the TT template file, the class comments are added
2 Plus attribute comments
Find this line of code foreach (Var edmproperty in simpleproperties)
Add our code underneath it.
foreach (Var edmproperty in simpleproperties) { if (edmproperty.documentation! = null && EdmProperty.Documentation.Summary = null) { summary=edmproperty.documentation.summary; } else { summary= ""; }
#>//<summary>// <#=summary#>/ </summary> <#= Codestringgenerator.property (Edmproperty) #>
While saving the TT template, our class attribute comments are added.
In fact, this TT template annotated principle is to read the edmx file (is an XML file) related comments to the Poco entity class annotated, if there is no comment in the EDMX, the database comment can not be added, the database and EDMX comments synchronization article, you can see this article EF architecture ~ Import the database comment into the model entity class.
EF Architecture ~ Add annotations to the entities generated by EF DbContext (T5 template app)