1<#@ Template debug="false"Hostspecific="true"Language="C #"#>2<#@ Assembly Name="System.Data"#>3<#@ Assembly Name="System.Xml"#>4<#@ Importnamespace="System.Collections.Generic"#>5<#@ Importnamespace="System.Data.SqlClient"#>6<#@ Importnamespace="System.Data"#>7<#@ Assembly Name="System.core"#>8<#@ Importnamespace="System.Linq"#>9 //Import multipleoutputhelper.ttinclude FileTen<# @include file="$ (solutiondir) \hclubmall.model\t4\multipleoutputhelper.ttinclude"#> One A<# - varManager =manager.create (Host, generationenvironment); - Manager. Startheader (); the#> - - - usingSystem; + usingSystem.Collections.Generic; - usingSystem.Linq; + usingSystem.Text; A at namespaceHclubmall.model - { -<# Manager. Endblock (); #> - -<# - stringconnectionstring="server=192.168.0.23;database=hclub1031;uid=sa;pwd=seindotnet;"; inSqlConnection conn =NewSqlConnection (connectionString); - Conn. Open (); to + stringSelectQuery ="SET fmtonly on; select * from @tableName; SET fmtonly OFF;"; -SqlCommand Command =NewSqlCommand (selectquery,conn); theSqlDataAdapter ad =NewSqlDataAdapter (command); *System.Data.DataSet ds =NewDataSet (); $System.Data.DataTable schema = conn. GetSchema ("Tables");Panax Notoginseng - foreach(System.Data.DataRow rowinchschema. Rows) the { + ds. Tables.clear (); A stringTb_name = row["table_name"]. ToString (); theCommand.commandtext = Selectquery.replace ("@tableName", row["table_name"]. ToString ()); + AD. FillSchema (Ds,schematype.mapped,tb_name); -Manager. Startnewfile (tb_name+". CS"); $#> $ [Serializable] - /// <summary> - ///Entity-<#=tb_name#> the /// </summary> - Public Partial class<#=tb_name#>Wuyi { the<# -PushIndent (" "); WuWriteLine ("#region Properties"); - foreach(DataColumn DCinchDs. tables[0]. Columns) About { $WriteLine ("// <summary>"); -WriteLine ("/// "); -WriteLine ("// </summary>"); -WriteLine (" Public"+ DC. Datatype.name + (DC. AllowDBNull && (DC. DataType.Name.ToLower ()! ="string") && (DC. DataType.Name.ToLower ()! ="byte[]") ?"? ":" ") + DC. ColumnName +"{get; set;}"); A } +WriteLine ("#endregion"); the popindent (); -#> $ } the<# the Manager. Endblock (); the } the Conn. Close (); -#> in the<# Manager. Startfooter (); #> the } About<# Manager. Endblock (); #> the the<# Manager. Process (true); #>
1. Need to refer to a foreign batch generated code template multipleoutputhelper.ttinclude
2. Create a T4 template and copy the above code into the newly created T4 template.
3.ctrl+s
4.:
Attention:
The Multipleoutputhelper.ttinclude project will error when it is on the desktop.
T4 template Batch Generation code files