动软代码生成器-C#数据库字段生成模板

<#@ template language="c#" HostSpecific="True" #>
<#@ output extension= ".cs" #>
<#
    TableHost host = (TableHost)(Host);
    host.Fieldlist.Sort(CodeCommon.CompareByintOrder);
#>
using System; 
using System.Text;
using System.Collections.Generic; 
using System.Data;
namespace <#= host.NameSpace #>.Model<# if( host.Folder.Length > 0) {#>.<#= host.Folder #><# } #>
{
    <# if( host.TableDescription.Length > 0) {#>
     //<#= host.TableDescription #>
    <# } #>
    public class <#= host.GetModelClass(host.TableName) #>
    {
                
          <# foreach (ColumnInfo c in host.Fieldlist)
        { #>/// <summary>
        /// <#= string.IsNullOrEmpty(c.Description) ? c.ColumnName : c.Description #>
        /// </summary>
        public <#= GetTypeName(c) #> <#= c.ColumnName #> { get;set; }
        
        <# } #>
    }
}


<#+
        private string GetTypeName(ColumnInfo c)
        {
            if(c.Nullable && (CodeCommon.DbTypeToCS(c.TypeName).ToString().ToLower())!="string") //如果字段可以为空,并且不是字符串类型 转换为可空类型
            {
               return CodeCommon.DbTypeToCS(c.TypeName)+"?";
            }
            
            else
            {
                 return CodeCommon.DbTypeToCS(c.TypeName);
            }
            
        }
        
#>

 

posted @ 2018-11-19 19:45  DeveloperLu  阅读(1131)  评论(0)    收藏  举报