首先先建立一个模板 名称随意 我起的“生成数据实体.cmt”
代码如下:
<#@ template language="c#" HostSpecific="True" #>
<#@ output extension= ".cs" #>
<#
TableHost host = (TableHost)(Host);
host.Fieldlist.Sort(CodeCommon.CompareByintOrder);
#>
using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
namespace <#= ClassName #>
{
<# if( host.TableDescription.Length > 0) {#>
//<#= host.TableDescription #>
<# } #>
[Table(Name = "<#= host.TableDescription #>")]
public class <#= host.TableName #>Model
{
[Column(Name = "<#= CodeCommon.GetFieldstrlist(host.Keys,true) #>",IsPrimaryKey = true,IsDbGenerated = true, AutoSync = AutoSync.OnInsert)]
<#
int i=0;
foreach (ColumnInfo c in host.Fieldlist)
{ #>
<# if(i!=0){ #>
[Column(Name = "<#= c.ColumnName #>")]
<# }#>
public <#= CodeCommon.DbTypeToCS(c.TypeName) #> <#= c.ColumnName #> { get; set; }
<# i++; } #>
}
}
<#+
string ClassName ="类名随意起";
#>