• 动软生成器 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
    
        }
    }

     如果主键没有生成成功,请手动在实体中加入

            /// <summary>
                    /// 获取实体中的主键列
                    /// </summary>
            public override Field[] GetPrimaryKeyFields()
            {
                return new Field[]
                {
    _.DIR_ID };
            }
    萌橙 你瞅啥?
  • 相关阅读:
    BestCoder Round #14
    poj 3400 Dropping the stones
    ZOJ1610_Count the Colors(段树/为段更新)
    cxSpreadBook 要么 cxSpreadSheet 设置文本格式
    Chromium Graphics Update in 2014(滑动)
    tomcat加载时报The web application [/dmscs] created a ThreadLocal with key of type
    08-使用for循环输出杨辉三角(循环)
    PHP中遍历stdclass object 及 json 总结[中国航天神舟十号以json形式向地面返回数据]
    MIPI CSI-2规范一——概述及层级
    练习1.16
  • 原文地址:https://www.cnblogs.com/daimaxuejia/p/10874713.html
Copyright © 2020-2023  润新知