动软生成器 Liger model生成模板

<#@ template language="c#" HostSpecific="True" #>
<#@ output extension= ".cs" #>
<#
    TableHost host = (TableHost)(Host);
    host.Fieldlist.Sort(CodeCommon.CompareByintOrder);
#>
using System;
using System.Data;
using System.Data.Common;
using Liger.Common;
using Liger.Data;
namespace <#= host.NameSpace #><# if( host.Folder.Length > 0) {#>.<#= host.Folder #><# } #>
{
    <# if( host.TableDescription.Length > 0) {#>
     //<#= host.TableDescription #>
    <# } #>
        /// <summary>
        /// 实体类 <#= host.GetModelClass(host.TableName) #>
        /// </summary>
    [Serializable]
        public class <#= host.GetModelClass(host.TableName) #>:Entity
    {    
         public <#= host.GetModelClass(host.TableName) #>(): base("<#= host.GetModelClass(host.TableName) #>")
         {         
        }         
            
           #region Model
        <# foreach (ColumnInfo c in host.Fieldlist)
        { #>
        private <#= CodeCommon.DbTypeToCS(c.TypeName) #><# if( CodeCommon.DbTypeToCS(c.TypeName)=="DateTime") {#>?<# } #> _<#= c.ColumnName #> ;  
        <# } #>
        
        <# foreach (ColumnInfo c in host.Fieldlist)
        { #>/// <summary>
        /// <#= string.IsNullOrEmpty(c.Description) ? c.ColumnName : c.Description #>
        /// </summary>
        public <#= CodeCommon.DbTypeToCS(c.TypeName) #><# if( CodeCommon.DbTypeToCS(c.TypeName)=="DateTime") {#>?<# } #> <#= c.ColumnName #> 
        {
                get{ return _<#= c.ColumnName #>; }
                set
                {
                this.OnPropertyValueChange(_.<#= c.ColumnName #>, _<#= c.ColumnName #>, value);
                this._<#= c.ColumnName #> = value;
            }
         }
        <# } #>
           #endregion
          
          
        #region Method
        <# foreach (ColumnInfo c in host.Fieldlist)
        { #>
        <# if( c.IsIdentity) {#>
          /// <summary>
        /// 获取实体中的标识列
        /// </summary>
        public override Field GetIdentityField()
        {
            return _.<#= c.ColumnName #>         ;
        }
        <# } #>
        <# } #>
      
 <# foreach (ColumnInfo c in host.Fieldlist)
        { #>
        <# if( c.IsPrimaryKey) {#>
         /// <summary>
        /// 获取实体中的主键列
        /// </summary>
        public override Field[] GetPrimaryKeyFields()
        {
            return new Field[] 
                       {
                         _.<#= c.ColumnName #>             };
        }
        <# } #>
        <# } #>
       
          
        /// <summary>
        /// 获取列信息
        /// </summary>
        public override Field[] GetFields()
        {
            return new Field[] {
          <# foreach (ColumnInfo c in host.Fieldlist)
        { #>
            _.<#= c.ColumnName #>,
        <# } #>
          };
        }
          
          /// <summary>
        /// 获取值信息
        /// </summary>
        public override object[] GetValues()
        {
            return new object[] {
                <# foreach (ColumnInfo c in host.Fieldlist)
        { #>
            _<#= c.ColumnName #>,
        <# } #>
            };
          }
          /// <summary>
        /// 设置字段值
        /// </summary>
        public override void SetValue(string fieldName, object value)
        {
            switch (fieldName)
            {
            <# foreach (ColumnInfo c in host.Fieldlist)
        { #>
                case "<#= c.ColumnName #>":
                    this._<#= c.ColumnName #> = DataHelper.ConvertValue<<#= CodeCommon.DbTypeToCS(c.TypeName) #><# if( CodeCommon.DbTypeToCS(c.TypeName)=="DateTime") {#>?<# } #>>(value);
                    break;
                    <# } #>
            }
        }
        
          /// <summary>
        /// 获取字段值
        /// </summary>
        public override object GetValue(string fieldName)
        {
            switch (fieldName)
            {
            <# foreach (ColumnInfo c in host.Fieldlist)
        { #>
                case "<#= c.ColumnName #>":
                    return this._<#= c.ColumnName #>;      
                     <# } #>          
                default:
                    return null;
            }
        }
        #endregion
          
          #region _Field
        /// <summary>
        /// 字段信息
        /// </summary>
        public class _
        {
            /// <summary>
            /// * 
            /// </summary>
            public readonly static Field All = new Field("*", "<#= host.GetModelClass(host.TableName) #>");
        <# foreach (ColumnInfo c in host.Fieldlist)
            { #>
            /// <summary>
            /// <#= string.IsNullOrEmpty(c.Description) ? c.ColumnName : c.Description #>
            /// </summary>
            public readonly static Field <#= c.ColumnName #> = new Field("<#= c.ColumnName #>", "<#= host.GetModelClass(host.TableName) #>", "<#= string.IsNullOrEmpty(c.Description) ? c.ColumnName : c.Description #>");
            <# } #>
        }
        #endregion

    }
}

猜你喜欢

转载自www.cnblogs.com/daimaxuejia/p/10874713.html