利用動軟代碼生成器 自動生成LINQ須要用的數據實體類 (轉)

首先先創建一個模板 名稱隨意 我起的「生成數據實體.cmt」c#

 

代碼以下:spa

<#@ 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 ="類名隨意起";
#>
相關文章
相關標籤/搜索