EF Architecture ~ Add annotations to the entities generated by EF DbContext (T5 template app)

Source: Internet
Author: User
Tags import database

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)

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.