NET EF基于MSSQL自动生成字段注释
1.下载文件,提取码: oft9
2.配置文件添加数据库连接
<connectionStrings> <add name="ConnStr" connectionString="data source=AAA;initial catalog=AAA;persist security info=True;user id=AAA;password=AAA;" providerName="System.Data.SqlClient"></add> </connectionStrings>
3.把 GetSummery.ttinclude 添加到根目录,在T4模板中引用
<#@ include file="GetSummery.ttinclude" #>
4.添加表注释:搜索[<#=codeStringGenerator.EntityClassOpening(entity)#>],添加如下代码
var summary = getTableSummery(code.Escape(entity)); if(summary == null || summary == "") { if(entity.Documentation != null && entity.Documentation.Summary != null) summary = entity.Documentation.Summary; else summary = entity.Name; }summary = Regex.Replace(summary, @"[\n\t\s]+", " ");
/// <summary> /// <#= summary #> /// </summary> <#=codeStringGenerator.EntityClassOpening(entity)#>
OR
/// <summary> /// <#= getTableSummery(code.Escape(entity)) #> /// </summary> <#=codeStringGenerator.EntityClassOpening(entity)#>
5.添加字段注释:搜索[<#=codeStringGenerator.Property(edmProperty)#>],添加如下代码
var summary = getColumnSummery(code.Escape(entity),code.Escape(edmProperty)); if(summary == null || summary == "") { if (edmProperty.Documentation != null && edmProperty.Documentation.Summary != null) summary = edmProperty.Documentation.Summary; else summary=""; }
summary = Regex.Replace(summary, @"[\n\t\s]+", " "); /// <summary> /// <#= summary #> /// </summary> <#=codeStringGenerator.Property(edmProperty)#>
OR
/// <summary> /// <#= getColumnSummery(code.Escape(entity),code.Escape(edmProperty)) #> /// </summary> <#=codeStringGenerator.Property(edmProperty)#>
6.Ctrl+s,就会自动更新