|
<#@ template language="C#" debug="True" hostspecific="True" #>
|
|
<#@ output extension=".cs" #>
|
|
<#@ assembly name="System.Data" #>
|
|
<#@ assembly name="System.xml" #>
|
|
<#@ import namespace="System.Collections.Generic" #>
|
|
<#@ import namespace="System.Data.SqlClient" #>
|
|
<#@ import namespace="System.Data" #>
|
|
<#@ import namespace="SqlSugar" #>
|
|
<#@ assembly name="D:\MyWork\Adient\Developement\X247_Adient\MirrorBox\bin\Debug\SqlSugar.dll" #>
|
|
<#@ include file="ModelAuto.ttinclude"#>
|
|
<# var manager = new Manager(Host, GenerationEnvironment, true) { OutputPath = Path.GetDirectoryName(Host.TemplateFile)}; #>
|
|
<#
|
|
string connectionString = "Data Source=192.168.0.238;Initial Catalog=X247;User ID=sa;Password=Leit2020;";
|
|
SqlConnection conn = new SqlConnection(connectionString);
|
|
conn.Open();
|
|
System.Data.DataTable schema = conn.GetSchema("TABLES");
|
|
string selectQuery = "select * from @tableName";
|
|
SqlCommand command = new SqlCommand(selectQuery,conn);
|
|
SqlDataAdapter ad = new SqlDataAdapter(command);
|
|
System.Data.DataSet ds = new DataSet();
|
|
|
|
string propQuery = "SELECT 表名=sobj.name,字段名=scol.name,字段说明=sprop.[value],是否可空=scol.isnullable FROM syscolumns as scol inner join sys.sysobjects as sobj on scol.id=sobj.id and sobj.xtype='U' and sobj.name<>'dtproperties' left join sys.extended_properties as sprop on scol.id=sprop.major_id and scol.colid=sprop.minor_id where sobj.name='@tableName' and scol.name='@columnName'";
|
|
SqlCommand command2 = new SqlCommand(propQuery,conn);
|
|
SqlDataAdapter ad2 = new SqlDataAdapter(command2);
|
|
System.Data.DataSet ds2 = new DataSet();
|
|
#>
|
|
|
|
<#
|
|
foreach(System.Data.DataRow row in schema.Rows)
|
|
{ #>
|
|
<#
|
|
manager.StartBlock(row["TABLE_NAME"]+".cs");
|
|
#>
|
|
using System;
|
|
namespace Leit.Model
|
|
{
|
|
/// <summary>
|
|
/// 数据表实体类:<#= row["TABLE_NAME"].ToString() #>
|
|
/// </summary>
|
|
[Serializable()]
|
|
public class <#= row["TABLE_NAME"].ToString() #> :EntityBase<<#= row["TABLE_NAME"].ToString() #>>
|
|
{
|
|
//当前代码为系统自动生成
|
|
|
|
|
|
<#
|
|
ds.Tables.Clear();
|
|
command.CommandText = selectQuery.Replace("@tableName",row["TABLE_NAME"].ToString());
|
|
ad.FillSchema(ds, SchemaType.Mapped, row["TABLE_NAME"].ToString());
|
|
|
|
string queryKey = "SELECT a.name FROM syscolumns a inner join sysobjects d on a.id = d.id where d.name =@tableName1 and exists(SELECT 1 FROM sysobjects where xtype = 'PK' and parent_obj = a.id and name in ( SELECT name FROM sysindexes WHERE indid in( SELECT indid FROM sysindexkeys WHERE id = a.id AND colid = a.colid)))";
|
|
string keyName = "";
|
|
string showKey="[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]";
|
|
using (SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = connectionString, DbType = SqlSugar.DbType.SqlServer, IsAutoCloseConnection = true }))
|
|
{
|
|
|
|
var tab = db.Ado.GetDataTable(queryKey, new { tableName1 = row["TABLE_NAME"].ToString() });
|
|
|
|
//string tablename= row["TABLE_NAME"].ToString();
|
|
if (tab.Rows.Count>0)
|
|
{
|
|
keyName = tab.Rows[0][0].ToString();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
foreach (DataColumn dc in ds.Tables[0].Columns)
|
|
{
|
|
#>
|
|
<#
|
|
ds2.Tables.Clear();
|
|
command2.CommandText = propQuery.Replace("@tableName",row["TABLE_NAME"].ToString());
|
|
command2.CommandText = command2.CommandText.Replace("@columnName",dc.ColumnName);
|
|
ad2.Fill(ds2);
|
|
|
|
|
|
|
|
|
|
|
|
#>
|
|
/// <summary>
|
|
/// <#= dc.DataType.Name #>:<#=ds2.Tables[0].Rows[0].ItemArray[2]#>
|
|
/// </summary>
|
|
<#=dc.ColumnName==keyName?showKey:""#>
|
|
public <#= dc.DataType.Name #><#=dc.DataType.Name!="String"?ds2.Tables[0].Rows[0].ItemArray[3].ToString()=="1"?"?":"":"" #> <#= dc.ColumnName #> {get;set;}
|
|
<# } #>
|
|
}
|
|
}
|
|
<# manager.EndBlock(); #>
|
|
|
|
<#
|
|
} #>
|
|
|
|
<#
|
|
manager.Process(true);
|
|
#>
|