实体的属性
1.给实体模型添加摘要(如图所示)
2、给实体中的属性添加摘要
3.修改t4模板,添加了类头注释
双击OADBModel.tt后再打开的代码中找到 如下所示的代码:
在上图红色区域添加如下代码:
//实现类注释
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)#>
4、修改t4模板,添加属性的注释
1 //此处实现属性的注释 2 var simpleProperties = typeMapper.GetSimpleProperties(entity); 3 if (simpleProperties.Any()) 4 { 5 foreach (var edmProperty in simpleProperties) 6 { 7 if (edmProperty.Documentation != null && edmProperty.Documentation.Summary != null) 8 { 9 summary=edmProperty.Documentation.Summary; 10 } 11 else 12 { 13 summary=""; 14 } 15 #> 16 /// <summary> 17 /// <#=summary#> 18 /// </summary> 19 <#=codeStringGenerator.Property(edmProperty)#>
5 修改t4模板,添加导航属性
<# foreach (var navigationProperty in navigationProperties) { if(navigationProperty.Documentation != null &&navigationProperty.Documentation.Summary != null) { summary=navigationProperty.Documentation.Summary; } else { summary=""; } #> /// <summary> /// <#=summary#> /// </summary> <#=codeStringGenerator.NavigationProperty(navigationProperty)#>
6.效果图如下: