CodeSmith生成C#通用实体类(不生成私有字段)

直接上cst模板代码

 

<%@ CodeTemplate Inherits="CodeTemplate" Language="C#" TargetLanguage="Text" Description="NetTiers main template." Debug="True" ResponseEncoding="UTF-8"%>

<%@ Assembly Name="SchemaExplorer"%>
<%@ Import Namespace="SchemaExplorer"%>
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
<%@ Property Name="Table" Type="TableSchema" DeepLoad="True" Optional="False" Category="01. Getting Started - Required" Description="Database that the tables views, and stored procedures should be based on. IMPORTANT!!! If SourceTables and SourceViews are left blank, the Entire Database will then be generated."%>
using System;

namespace Model
{
    ///<summary>
    ///<%= Table.Name %>的实体类
    ///</summary>
    public class <%= GetTableName(Table.Name)%> 
    {
        <%foreach(ColumnSchema col in Table.Columns){ %>
        /// <summary>
        /// <%= col.Description %>
        /// </summary>
        public <%= CSharpAlias[col.SystemType.FullName] %><%= col.AllowDBNull&&CSharpAlias[col.SystemType.FullName]!="string"?"?":"" %>  <%= col.Name %>{ get;set; }
        <% } %>
    }
}
<script runat="template">
   
    public string GetTableName(string tName)
    {
        string rName="";
        string[] names=tName.Split('_');
        return tName;
    }
</script>

 

 

右边Table属性里选择要生成的表之后点生成即可

效果如下:

 

posted @ 2019-07-02 22:57  那一片蓝海  阅读(483)  评论(0)    收藏  举报