zoukankan      html  css  js  c++  java
  • t4 根据表名数组生成实体

    <#@ template debug="false" hostspecific="true" language="C#" #>
    <#@ assembly name="System.Core.dll" #>
    <#@ assembly name="System.Data.dll" #>
    <#@ assembly name="System.Data.DataSetExtensions.dll" #>
    <#@ assembly name="System.Xml.dll" #>
    <#@ import namespace="System" #>
    <#@ import namespace="System.Xml" #>
    <#@ import namespace="System.Linq" #>
    <#@ import namespace="System.Data" #>
    <#@ import namespace="System.Data.SqlClient" #>
    <#@ import namespace="System.Collections.Generic" #>
    <#@ import namespace="System.IO" #>
    <#@include file="$(ProjectDir)T4includeDbHelper.ttinclude"#> 
    <#@include file="$(ProjectDir)T4includeMultipleOutputHelper.ttinclude"#> 
    <#@ output extension="/" #>
    <#    
        var manager = Manager.Create(Host, GenerationEnvironment);
        string projectPath = Host.ResolveAssemblyReference("$(ProjectDir)");
       
        foreach(string item in config.TableName )
        {
            manager.StartNewFile(item+".cs");
    #>
    //------------------------------------------------------------------------------
    // <auto-generated>
    //     此代码由T4模板自动生成
    //       生成时间 <#=            DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")#> by 大聪哥
    //     对此文件的更改可能会导致不正确的行为,并且如果
    //     重新生成代码,这些更改将会丢失。
    // </auto-generated>
    //------------------------------------------------------------------------------
    
    using System;
    namespace T4.Entities
    {    
    
        public class <#=            item#>
        {
            <#        foreach(DbColumn column in DbHelper.GetDbColumns(config.ConnectionString, config.DbDatabase, item)){#>
    
            /// <summary>
            /// <#=                column.Remark#>
            /// </summary>        
            public <#=                column.CSharpType#><#            if(column.CommonType.IsValueType && column.IsNullable){#>?<#            }#> <#=                column.ColumnName#> { get; set; }
            <#        }#> 
          
        }
    }
    
      <#    }#>
    <#    manager.EndBlock(); #>
    <#    manager.Process(true); #>
    <#+
        public class config
        {
            public static readonly string ConnectionString="server=192.168.0.101,1433\sql2008R2;database=best;uid=sa;pwd=landa";
            public static readonly string DbDatabase="best";
            public static readonly List<string> TableName=new List<string>(){
                    "X6_Recruitment_InterviewRegistration",
                    "X6_Recruitment_InterviewRegistration_RelativesFriends",
                    "X6_Recruitment_InterviewRegistration_EduExperienceList",
                    "X6_Recruitment_InterviewRegistration_WorkExperienceList",
                    "X6_Recruitment_InterviewRegistration_TitleList",
                    "X6_Recruitment_InterviewRegistration_Spouse",
                    "X6_Recruitment_InterviewRegistration_OtherMembers",
                    "X6_Recruitment_InterviewRegistration_OtherInfo"
                    };
        }
    #>
  • 相关阅读:
    Java基本数据类型之间转换
    python 元组tuple
    python 列表List
    python 字符串
    python for循环
    python break/continue
    python while循环
    python条件判断if/else
    python运算符
    python变量
  • 原文地址:https://www.cnblogs.com/gaocong/p/7375553.html
Copyright © 2011-2022 走看看